470,833 Members | 1,858 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Enumerating Windows

Jay
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)

Jun 8 '06 #1
5 1208
Jay wrote:
dwID2 = (LPDWORD)calloc(1,sizeof(DWORD));
Why do you do a dynamic memory allocation here? The size of your object
is known, just create your variable on the stack:

unsigned process_id;
GetWindowThreadProcessId(hwnd, &process_id);
*currProcId = locHPStruct->procID;


currProcId is uninitialized, yet you're resolving it, as if it was a
valid pointer. This is causing your Access Violation. Once again,
there's no reason to use a pointer here. How about

unsigned currProcId = locHPStruct->procID;

Tom
Jun 8 '06 #2
Jay

Tamas Demjen wrote:
Jay wrote:
dwID2 = (LPDWORD)calloc(1,sizeof(DWORD));


Why do you do a dynamic memory allocation here? The size of your object
is known, just create your variable on the stack:

unsigned process_id;
GetWindowThreadProcessId(hwnd, &process_id);
*currProcId = locHPStruct->procID;


currProcId is uninitialized, yet you're resolving it, as if it was a
valid pointer. This is causing your Access Violation. Once again,
there's no reason to use a pointer here. How about

unsigned currProcId = locHPStruct->procID;

Tom

Tom,
Thanks for the reply, I don't why I was doing all that! I have
another question though. Now that I have that resolved, I have the
following lines of code:
retVal =
CreateProcess(NULL,modName,NULL,NULL,FALSE,NULL,NU LL,NULL,&si,&pi);
procID = pi.dwProcessId;
HPStruct.procID = procID;
HPStruct.WindHandle = 0;
EnumWindows((WNDENUMPROC)EnumOpenWindows,(LPARAM)& HPStruct);
As you can see, I am enumerating the windows almost immediately after
creating the process. Why is it that the window handle id for the newly
created process is not in the list of processes that is enumerated? The
output from the function is below:
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=3660
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1300
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1276
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1276
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=3740
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=2376
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=2320
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=3660
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=3660
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=3660
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=3660
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=2156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1068
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1400
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1252
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1276
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1276
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1260
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1276
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1276
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1276
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1244
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=788
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1848
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1460
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156
*******************<EnumOpenWindows>************** *****
currProcId=2512 dwID2=1156

Any ideas?

Thanks,
Jay
(patelj27b at gmail dot com)

Jun 8 '06 #3
Jay wrote:
Now that I have that resolved, I have the
following lines of code:
retVal =
CreateProcess(NULL,modName,NULL,NULL,FALSE,NULL,NU LL,NULL,&si,&pi);
procID = pi.dwProcessId;
HPStruct.procID = procID;
HPStruct.WindHandle = 0;
EnumWindows((WNDENUMPROC)EnumOpenWindows,(LPARAM)& HPStruct);
As you can see, I am enumerating the windows almost immediately after
creating the process.


Probably that's the problem. CreateProcess returns almost immediately,
well before the new process has a chance to open a window. You might
want to wait for the process to launch:

CreateProcess(...);
HPStruct.procID = pi.dwProcessId;
HPStruct.WindHandle = 0;
WaitForSingleObject(pi.hProcess, INFINITE);
EnumWindows(...);

Tom
Jun 8 '06 #4
Tamas Demjen wrote:
WaitForSingleObject(pi.hProcess, INFINITE);


Sorry this is not good, it waits for the process to exit. This is not a
solution.

Well I don't know, but the problem seems to be that the window shows up
later in time, after EnumWindows has a chance to see it. You might want
to repeat the window enumeration a few times until it shows up, with a
little bit of Sleep() in between attempts. This would be my first guess.

Tom
Jun 8 '06 #5
Tamas Demjen wrote:
Probably that's the problem. CreateProcess returns almost immediately,
well before the new process has a chance to open a window. You might
want to wait for the process to launch:


I think I've found the correct solution, it's WaitForInputIdle:

CreateProcess(...);
HPStruct.procID = pi.dwProcessId;
HPStruct.WindHandle = 0;
WaitForInputIdle(pi.hProcess, INFINITE);
EnumWindows(...);
Quoted from MSDN:

The WaitForInputIdle function enables a thread to suspend its execution
until a specified process has finished its initialization and is waiting
for user input with no input pending. This can be useful for
synchronizing a parent process and a newly created child process. When a
parent process creates a child process, the CreateProcess function
returns without waiting for the child process to finish its
initialization. Before trying to communicate with the child process, the
parent process can use WaitForInputIdle to determine when the child's
initialization has been completed. For example, the parent process
should use WaitForInputIdle before trying to find a window associated
with the child process.

Tom
Jun 8 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Brett Mostert | last post: by
7 posts views Thread by Rohan Ranade | last post: by
4 posts views Thread by Brian P. Bailey | last post: by
4 posts views Thread by Brett Mostert | last post: by
1 post views Thread by Jay | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.