Problem:
You're creating trouble for yourself because of attempting to dynamically allocate the POINT
object with malloc
. BTW you do not always need dynamic allocation and to initialize any struct you do not need to use malloc
as you pointed in the comments, you can just create the object directly.
Solution:
As tkausl
pointed in the comments, POINT
is created in the same way as any other struct.
Some examples on how creating a POINT
:
int main()
{
int someX = 100;
int someY = 100;
RECT testRect1 = {0,0,200,200};
RECT testRect2 = {150,150,350,350};
POINT p1{someX,someY};
POINT p2 = {someX,someY};
POINT p3;
p3.x = someX;
p3.y = someY;
std::cout << (bool) PtInRect(&testRect1,p1) << std::endl;
std::cout << (bool) PtInRect(&testRect1,p2) << std::endl;
std::cout << (bool) PtInRect(&testRect1,p3) << std::endl;
std::cout << (bool) PtInRect(&testRect1,{someX,someY}) << std::endl;
std::cout << (bool) PtInRect(&testRect2,p1) << std::endl;
std::cout << (bool) PtInRect(&testRect2,p2) << std::endl;
std::cout << (bool) PtInRect(&testRect2,p3) << std::endl;
std::cout << (bool) PtInRect(&testRect2,{someX,someY}) << std::endl;
}