Re: GetCursorPos returns 0
AN LPPOINT is a pointer to a POINT struct. However you have just a pointer and no POINT struct.
Change LPPOINT to POINT and call GetCursorPos with the address of that POINT struct
POINT point
GetCursorPos(&point)
Re: GetCursorPos returns 0
Code:
x = point->x;
y = point->y;
I got the following errors now:
18: base operand of `->' has non-pointer type `POINT'
19: base operand of `->' has non-pointer type `POINT'
What does that mean?
Thankyou for you help
Re: GetCursorPos returns 0
point.x not point->x
point is a struct. lppoint was a pointer.
You access a structs members with the dot operator
Re: GetCursorPos returns 0
You're not allocating any memory for lpPoint.
Code:
lpPoint = (LPPOINT)GlobalAlloc(GPTR, sizeof(POINT));
Re: GetCursorPos returns 0
Thx for you help!
The script is working now:
Code:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
POINT point;
int x;
int y;
while(true) {
if(!GetCursorPos(&point))
{
cout << "An error occurred: " << endl;
cout << GetLastError();
}
else
{
x = point.x;
y = point.y;
cout << x << endl;
cout << y << endl;
}
Sleep(100);
system("cls");
}
return 0;
}
Re: GetCursorPos returns 0
Quote:
Originally Posted by
BobS0327
You're not allocating any memory for lpPoint.
Code:
lpPoint = (LPPOINT)GlobalAlloc(GPTR, sizeof(POINT));
Code:
POINT Point;
if(!GetCursorPos(&Point))
would be simpler in this case. If you really want to put it on the heap, new would be simpler than GlobalAlloc.
Re: GetCursorPos returns 0
You should get out of the habit of calling it a "script" too. You're a real programmer now. You're writing a "program".
Re: GetCursorPos returns 0
Quote:
Originally Posted by
BobS0327
You're not allocating any memory for lpPoint.
Code:
lpPoint = (LPPOINT)GlobalAlloc(GPTR, sizeof(POINT));
Please read this link:
http://www.flounder.com/badprogram.h...%20reason%20to
Even though you used GlobalAlloc, the article still is valid with respect to allocating memory when you do not need to do it.
Regards,
Paul McKenzie
Re: GetCursorPos returns 0
Quote:
Originally Posted by
Paul McKenzie
Actually, Microsoft recommends using heap functions instead of global and local functions.
Re: GetCursorPos returns 0
If you wanted to show how its done with a pointer then it would have been simpler to do :-
POINT point;
LPPOINT lppoint = &point;
What is the point in dynamically allocating a POINT struct in this single function program, when a simpler stack allocated object will suffice, especially when the OP said how new to C++ he was.