开发者

C++ How to get process ID from filename of DLL(windows)?

开发者 https://www.devze.com 2023-03-18 07:27 出处:网络
how can I get a process ID from a filename? Like: int processId = getProcessIdByFileName(\"Network.dll\");

how can I get a process ID from a filename? Like: int processId = getProcessIdByFileName("Network.dll"); Btw, which datatype has the process ID?

Extended info: I have the source code of a DLL. This DLL gets 开发者_如何学Pythonloaded to an application, like a few other DLL's. I want to hook the other DLL's functions. Therefore I need the process ID of them(is there a process ID for each DLL if they all run under one application?

How could I call functions of the other DLL's inside of my DLL? How to get a handle to them?


DLLs do not have process IDs. A DLL may be loaded into multiple processes, or none at all. A DLL may be loaded into a process, later unloaded, and then loaded again. It is meaningless to talk of the process ID of a DLL. What are you actually trying to do?


This isn't possible, and here's why. DLLs are shared between processes. It may only have one "owning" process, it may have many. You CAN determine which dlls a program has loaded (e.g. dependency walker) however you can't determine which programs (if any) are attached to a DLL.


Process ID in Windows is not staticaly embedded inside file, its a property that any DLL, EXE or executable has once its running. Check Toolhelp API, you`ll find all answers there.

To call functions from other DLL you need to load that DLL dynamicaly, check here for an example http://www.codeproject.com/KB/DLL/dynamicdllloading.aspx


DLLs are not run, they are loaded by processes so this is not possible. You can however look for the PID of a process by using its path or name ie. Get PID of "explorer.exe"

You could get the PID's of the processes that have loaded the specific DLL. ie.

int PIDs[128];
GetDependentProcesses(PIDs, "Kernel32.dll"); //Custom function, not built in

for(int x = 0; x < 128; x++)
{
   cout << PIDs[x] << " Depends on Kernel32.dll\n";
}

And you cant hook a DLL, only a process.

0

精彩评论

暂无评论...
验证码 换一张
取 消