开发者

Identify which executable is throwing a runtime error

开发者 https://www.devze.com 2023-01-03 19:19 出处:网络
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 co

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

精彩评论

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