Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Find Which DLL / EXE Created a Window

, 8 Apr 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
How to find which DLL / EXE created a Window

The GetWindowModuleFileName() functions can be used to find which EXE or DLL has created a window. But the problem with this function is that it will not work across processes.

Whenever we create a window, we have to pass an HINSTANCE into it. Later, we can use GetWindowLong to get that HINSTANCE. Actually the HINSTANCE is nothing but the HMODULE itself. So if we get the hinstance of a window, we can pass this handle to the GetModuleFileNameEx() and simply get the name of the window from other processes as well.

CString MyGetWindowModuleFileName( HANDLE hwindowhandle )
    CString csModuleName;
    DWORD dwProcessId;
    GetWindowThreadProcessId( hwindowhandle, &dwProcessId );
    HINSTANCEhModule = (HINSTANCE)GetWindowLong( hwindowhandle, GWL_HINSTANCE );
    if(hModule == NULL)
        return csModuleName;
        FALSE, dwProcessId );
    if( hProcess == NULL )
        return csModuleName;
    BOOL bReturn = GetModuleFileNameEx( hProcess, hModule,
        csModuleName.GetBuffer( MAX_PATH), MAX_PATH );
    return csModuleName;


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
Singapore Singapore
No Biography provided

Comments and Discussions

GeneralThank you PinmemberPepsibot26-Jan-10 8:36 
GeneralRe: Thank you PinmemberPepsibot26-Jan-10 8:39 
GeneralMy vote of 1 PinmemberBlkbam10-Apr-09 6:32 
GeneralRe: My vote of 1 Pinmemberonly_jack26-Apr-09 10:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 8 Apr 2009
Article Copyright 2009 by Naveen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid