Click here to Skip to main content
13,138,881 members (54,444 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


17 bookmarked
Posted 8 Apr 2009

Find Which DLL / EXE Created a Window

, 8 Apr 2009
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

You may also be interested in...


Comments and Discussions

GeneralThank you Pin
Pepsibot26-Jan-10 7:36
memberPepsibot26-Jan-10 7:36 
GeneralRe: Thank you Pin
Pepsibot26-Jan-10 7:39
memberPepsibot26-Jan-10 7:39 
GeneralMy vote of 1 Pin
Blkbam10-Apr-09 5:32
memberBlkbam10-Apr-09 5:32 
GeneralRe: My vote of 1 Pin
only_jack26-Apr-09 9:22
memberonly_jack26-Apr-09 9:22 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170915.1 | Last Updated 8 Apr 2009
Article Copyright 2009 by Naveen
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid