Click here to Skip to main content
11,923,676 members (62,902 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


17 bookmarked

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

You may also be interested in...

Comments and Discussions

GeneralThank you Pin
Pepsibot26-Jan-10 8:36
memberPepsibot26-Jan-10 8:36 
GeneralRe: Thank you Pin
Pepsibot26-Jan-10 8:39
memberPepsibot26-Jan-10 8:39 
GeneralMy vote of 1 Pin
Blkbam10-Apr-09 6:32
memberBlkbam10-Apr-09 6:32 
GeneralRe: My vote of 1 Pin
only_jack26-Apr-09 10:22
memberonly_jack26-Apr-09 10: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.

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