The code worked all along. Somehow I manage to get Visual C++ Express not hit the break point on the final return statement and it appeared to run for ever.
In the e
EnumWindowsProc
should never run infinitely.
It should run until:
So I suspect it appears to be running infinitely for you because of memory corruption or a memory access violation.
Your printf should be using %s not %S.
BOOL CALLBACK EnumWindowsProc(HWND hWnd, long lParam) {
TCHAR buff[255];
if (IsWindowVisible(hWnd)) {
GetWindowText(hWnd, (LPWSTR) buff, 254);
printf("%s\n", buff);//<--- %s means use TCHAR* which is WCHAR* in your case
}
return TRUE;
}
Also you shouldn't need to be casting your buff as a LPWSTR. If your buff is somehow a CHAR buffer then you need to compile with the Unicode character set.