Click here to Skip to main content
11,576,293 members (61,381 online)
Click here to Skip to main content

Tagged as

Find Which DLL / EXE Created a Window

, 8 Apr 2009 CPOL 14.2K 17
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;
    }
    HANDLE hProcess = OpenProcess(PROCESS_VM_READPROCESS_QUERY_INFORMATION,
        FALSE, dwProcessId );
    if( hProcess == NULL )
    {
        return csModuleName;
    }
    BOOL bReturn = GetModuleFileNameEx( hProcess, hModule,
        csModuleName.GetBuffer( MAX_PATH), MAX_PATH );
    csModuleName.ReleaseBuffer();
    CloseHandle(hProcess);
    return csModuleName;
}

License

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

Share

About the Author

Naveen
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    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
Web04 | 2.8.150603.1 | Last Updated 8 Apr 2009
Article Copyright 2009 by Naveen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid