views:

30

answers:

2

I have a program that is throwing a run-time error dialog. Is there a way to programmatically detect which executable is the parent of this dialog box from another process?

+1  A: 

Update: You can get a process name from a window handle using GetWindowModuleFileName

To find the find handle, you could get the DesktopWindow and then enumerate the ones until you find the one with the error message.

Preet Sangha
Byron Whitlock
+1  A: 

Yes. The code would be something like this (error checking omitted):

HWND hWindow = FindWindow( NULL, windowName );
DWORD processId;
GetWindowTheadProcessId( hWindow, &processId );
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION, FALSE, processId );
GetModuleFileNameEx( hProcess, NULL, buffer, BUFFER_SIZE );

The GetProcessImageFileName() function is preferrable to GetModuleFileNameEx() if you aren't concerned with older platforms.

Peter Ruderman
Peter, this worked like a charm. Thanks for the help.
Byron Whitlock