473,388 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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 1327
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brett Mostert | last post by:
Hi, I need to be able to Enumerate through Printer Drivers, ports, printers and so fourth. And even add printers, ports, and drivers and setup printers. Sofar i can do all of the following...
7
by: Rohan Ranade | last post by:
I am trying to implement a crawler in C# that scans all the shared folders in remote computers in a windows network. Are there classes in .NET to do this directly? Please help. Thank You. Rohan
4
by: Brian P. Bailey | last post by:
Hello, I'm trying to enumerate the fixed-pitch font families installed on a system. I am _not_ trying to create a generic monospaced font. I've tried looking at: FontFamily...
4
by: Brett Mostert | last post by:
Hi, I need to be able to Enumerate through Printer Drivers, ports, printers and so fourth. And even add printers, ports, and drivers and setup printers. Sofar i can do all of the following...
2
by: Tony | last post by:
I have this problem - I have a hashtable, containing a list of filenames. Every 60 seconds, I have a thread that enumerates thru this hashtable, and based on some simple logic, some of the items...
4
by: Shayne H | last post by:
What is the best way to enumerate a grouping of strings? The way I have been doing it is: Public Enum PlatformID Unknown Win16 Win32 Win32NT WinCE End Enum
0
by: wifetalks | last post by:
I'm enumerating the computers in the domain to a listview control on my form, but how do I include the comments. Like what you would see in Windows Explorer when you browse the domain. On our...
1
by: Jay | last post by:
Hey There, I am trying to get a list of the open windows from a Windows Service. My initial code was written in a regular server and the window listing function EnumWindows worked fine, but when I...
4
by: nagar | last post by:
On certain occasions I get COM exceptions errors when enumerating the Windows Explorer active windows Some customers reported the error System.OutOfMemoryException: Retrieving the COM class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.