开发者

Identify which executable is throwing a runtime error

I have a program that is throwing a run-time error dialog. Is there a way to programmatically detect which executable is the p开发者_如何学JAVAarent of this dialog box from another process?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜