2013-04-03 75 views
0

Stack around the variable "rc" was corrupted错误,试图测试此代码时损坏的堆栈(使用返回坐标那里移动鼠标)
请参阅下面的代码:同时使用MapWindowPoints

int TestPluginAPI::getmidX() 
{ 
//RECT rect; 
HWND hWnd; 
hWnd = getBrowserHwnd(); 
RECT rc; 
if(GetClientRect(hWnd, &rc)) // get client coords 
{ 
MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc.left), 2); // convert top-left x 
MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc.right), 2); // convert bottom-right x 
MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc.top), 2); // convert top-left y 
MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc.bottom), 2); // convert bottom-right y 
return rc.left; 
} 
else {return 0;} 
} 

你能告诉我,什么是错的?

+1

值得在使用它们之前阅读这些函数的文档:http://msdn.microsoft.com/en-us/library/windows/desktop/ dd145046(v = vs.85).aspx – LihO 2013-04-03 22:22:14

+1

当你传递&rc.bottom并且说有两点时,你的堆栈会被破坏。只有一个。向微软购买一支雪茄,让你远离深沉的麻烦。 – 2013-04-03 22:26:14

+0

为了好奇,你的意思是什么样的可怕的麻烦? – 2013-04-03 22:42:18

回答

3

是的,它应该是眼前这个

if(GetClientRect(hWnd, &rc)) // get client coords 
{ 
    MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc), 2); 
    return rc.left; 
} 

的矩形是两个点(左上和右下)。因此,您只需调用一次MapWindowPoints,计数为2.

+0

它..有道理,现在将测试riiiiight – 2013-04-03 22:24:13

+0

是的,这是工作,thx。 – 2013-04-03 22:32:58