user2417635
user2417635

Reputation:

Is dll present in process c++

i want to check if a certain DLL is present in a certain process for exmple: is user32.dll present in explorer.exe,i used this code to get the process PID:

DWORD GetProcId(char* ProcName)
{
PROCESSENTRY32   pe32;
HANDLE         hSnapshot = NULL;

pe32.dwSize = sizeof( PROCESSENTRY32 );
hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

if( Process32First( hSnapshot, &pe32 ) )
{
    do{
        if( strcmp( pe32.szExeFile, ProcName ) == 0 )
            break;
    }while( Process32Next( hSnapshot, &pe32 ) );
}

if( hSnapshot != INVALID_HANDLE_VALUE )
    CloseHandle( hSnapshot );

DWORD ProcId = pe32.th32ProcessID;
return ProcId;
}

What can i use to check if a dll is present in this PID?

Upvotes: 0

Views: 168

Answers (2)

David
David

Reputation: 243

Use Module32First/Next the same way you used Process32First/Next

bool IsModulePresent(unsigned long procid,char* moduleName)
{
    HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,procid);
    MODULEENTRY32 pModule;
    pModule.dwSize = sizeof(MODULEENTRY32);

    Module32First(hSnapShot,&pModule);
    do {
        if( !strcmp(pModule.szModule,moduleName) )
            return true;

    }while(Module32Next(hSnapShot,&pModule));

    return false;
}

Upvotes: 1

shf301
shf301

Reputation: 31404

Use Module32First/Module32Next to walk through all of the modules in a process snapshot. There is a detailed example at MSDN.

Upvotes: 0

Related Questions