Enumerating Windows
Hey There,
I have this function that is called through EnumWindows:
BOOL CALLBACK EnumOpenWindows(HWND hwnd, LPARAM lParam)
{
DWORD dwID;
LPDWORD dwID2;
LPDWORD currProcId;
FILE* fp;
struct _HwndProcStruct* locHPStruct;
fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
fprintf(fp,"*******************<EnumOpenWindows>*******************\n");
fclose(fp);
dwID2 = (LPDWORD)calloc(1,sizeof(DWORD));
locHPStruct = (struct _HwndProcStruct*)lParam;
*currProcId = locHPStruct->procID;
*dwID2 = 0;
GetWindowThreadProcessId(hwnd, dwID2);
fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
fprintf(fp,"currProcId=%d dwID2=%d\n",*currProcId,*dwID2);
fclose(fp);
if(*dwID2 == *currProcId)
{
locHPStruct->WindHandle = hwnd;
free(dwID2);
return FALSE;
}
else
{
free(dwID2);
return TRUE;
}
}
I'm using it to try to find the HWND from a Process ID. For some
reason, when I have the file print statements below
"GetWindowThreadProcessId(hwnd, dwID2); " the function will generate
the following error:
Unhandled exception at 0x0040126c in SysTrayApp.exe: 0xC0000005: Access
violation writing location 0x000809be.
But if I comment out those three lines, then the function executes
normally. What could cause this?
-Jay
(patelj27b at gmail dot com)