Reputation: 1147
I have trying to hook WinApi using AppInitHook. So it works perfectly but I need to hook only some processes not all. The question is how to get process id where dll is loaded? For example dll was loaded for MyApp.exe, how can I get this process id?
Regarsd!
ps sorry im not hardcore WinApi programmer and my question mybe so easy, but its now hard for me)
Upvotes: 2
Views: 7758
Reputation: 15030
To do something when DLL is loaded, you need to define DllMain function as in the code example below. Then you can get process ID when the process gets attached to the DLL (also in the code example).
BOOL APIENTRY DllMain(HMODULE hModule, DWORD reasonForCall, LPVOID lpReserved)
{
hModule; lpReserved;
switch (reasonForCall) {
case DLL_PROCESS_ATTACH:
{
uint32_t pid = GetCurrentProcessId();
// Do something depending on the process ID in |pid|
break;
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Upvotes: 0