VC6下用 Debug 模式執行EnumWindow 發生如下圖有關暫存器 ESP 的錯誤,Release 模式又ok
C++:
-
EnumWindows((WNDENUMPROC)EnumWindowsProc, 0);
-
-
BOOL EnumWindowsProc(HWND hWnd, long lParam)
-
{
-
char Buff[1000], NameOfClass[1000];
-
HWND hChild;
-
GetWindowText(hWnd, Buff, 1000);
-
GetClassName(hWnd, NameOfClass, 1000);
-
if (strcmp(NameOfClass, "Notepad") == 0) {
-
hChild = GetWindow(hWnd, GW_CHILD);
-
GetClassName(hChild, NameOfClass, 1000);
-
GetWindowText(hChild, Buff, 1000);
-
g_hWnd = hChild;
-
return FALSE;
-
}
-
return TRUE;
-
}

Solution
do NOT use the compile option "/Gz", this option changes the calling convention
/Gd __cdecl calling convention
/Gr __fastcall calling convention
/Gz __stdcall calling convention