2013-04-03 74 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