Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 16th, 2005, 12:32 PM   #1
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 318
Rep Power: 4 Klarre is on a distinguished road
[WIN32] Inline asm call to GetCursorPos

I am trying to call this function using inline assembly:
BOOL GetCursorPos(LPPOINT lpPoint);
I began doing it using C++, and it works fine, using this code:
#include <windows.h>
int main()
{
	// C++
	while(true)
	{
		POINT cursorPos;
		GetCursorPos(&cursorPos);
	}

	return 0;
}
But now I wish to do the same thing using inline assembly. I found it a little bit trickier! My thoughts were - "It want an adress to a struct that only contains two int's (actually long's). How do I do this?" I wrote this code...
#include <windows.h>

int main()
{
	// Assembly
	while(true)
	{
		int cursorPos[2];
		cursorPos[0] = cursorPos[1] = 0;

		_asm
		{
			lea eax, cursorPos
			push eax
			call GetCursorPos
		}
	}

	return 0;
}
...but Visual Studio gives me this error: "Unhandled exception at 0x0042e484 in test.exe: 0xC0000005: Access violation writing location 0xfffffed0." And it comes when calling the GetCursorPos.

Where did my thoughts went wrong? Thanks for your help!

/Klarre
Klarre is online now   Reply With Quote
Old Nov 16th, 2005, 1:24 PM   #2
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Uhmm POINT is a structure, which contains an x and a y coordinate. GetCursorPos will give you a structure back. I'm not sure how to do that, but that's what's going wrong if I'm not mistaken.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Nov 16th, 2005, 1:45 PM   #3
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
I'm definitely not an assembly expert, but can't you do just this:
	while(true) {
		POINT cursorPos;

		_asm {
			push cursorPos
			call GetCursorPos
		}
	}

@nnxion: Using an array or POINT doesn't really matter i believe, in the end it are just two integers.
Polyphemus_ is offline   Reply With Quote
Old Nov 16th, 2005, 2:23 PM   #4
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 318
Rep Power: 4 Klarre is on a distinguished road
Quote:
Originally Posted by Polyphemus_
I'm definitely not an assembly expert, but can't you do just this:
	while(true) {
		POINT cursorPos;

		_asm {
			push cursorPos
			call GetCursorPos
		}
	}

@nnxion: Using an array or POINT doesn't really matter i believe, in the end it are just two integers.
Actually this code should not be used inline (I am just coding inline because it is easier to debug). Therefor I can not make use of any structs or classes.
Your proposal do not work. But thanks anyway!

/Klarre
Klarre is online now   Reply With Quote
Old Nov 16th, 2005, 2:38 PM   #5
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
You are just coding inline because it is easier to debug? That's the most ridiculous statement I have ever heard about inline assembly.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Nov 16th, 2005, 2:55 PM   #6
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 318
Rep Power: 4 Klarre is on a distinguished road
Quote:
Originally Posted by nnxion
You are just coding inline because it is easier to debug? That's the most ridiculous statement I have ever heard about inline assembly.
Oh! Haha! I guess I forgot to tell you that I am working on an assembly application. I am just testing my code inline before I implement it in the real app!

/Klarre
Klarre is online now   Reply With Quote
Old Nov 16th, 2005, 6:29 PM   #7
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 318
Rep Power: 4 Klarre is on a distinguished road
Problem solved!

Found that it is possible to create structs in asm. That helped alot!

/Klarre
Klarre is online now   Reply With Quote
Old Nov 17th, 2005, 12:37 PM   #8
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by Polyphemus_
@nnxion: Using an array or POINT doesn't really matter i believe, in the end it are just two integers.
Well there's the overhead of a structure which will make it different from just two integers.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:56 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC