如何在加载的dll中找到进程ID [英] How do I find the process id inside a loaded dll

查看:252
本文介绍了如何在加载的dll中找到进程ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个插件,它基本上是一个加载的DLL。我可能有两个加载插件的同一个应用程序的实例。我希望能够从加载DLL的应用程序中找到进程ID。

I am working with a plugin which is basically a loaded DLL. I may have both instances of the same application that loads the plugin. I want to be able to find out the process ID from the application that loaded the DLL.

推荐答案

使用进程(System.Diagnostics):

Using process (System.Diagnostics):
// Get the current process.
Process currentProcess = Process.GetCurrentProcess();

//Process id
int Id = currentprocess.Id;
...


问题不是很清楚,但你可能会误解进程和DLL。首先,在.NET中,DLL的概念变得无关紧要。有流程;中心概念是程序集,而DLL或EXE只是一些模块。使用VS,程序集只有一个模块,但是可以有更多,VS不直接支持,但仍然可以完成。



现在,汇编确实不了解这些过程。相同的组件(以及因此其模块)可以在不同的过程中执行。无论您的代码在何处,在条目程序集中,它都可以按照解决方案1告诉您的方式请求当前进程。它不会给你任何东西,除非你以某种方式与其他进程或某些进程间工具进行通信,这些工具统称为IPC,即使这样你也不需要ID。如果你解释你的最终目标,你可以获得更多帮助。



-SA
The question is not quite clear, but it's possible that you misunderstand processes and DLLs. First of all, in .NET, the concept of "DLL" is made insignificant. There are processes; and the central concept is assembly, and DLL or EXE are just some modules. With VS, an assembly has only one module, but there can be more, which is not directly supported by VS, but still can be done.

Now, assembly does not "know" about the processes. The same assembly (and hence its module) can be executed in different processes. No matter where your code is, in the entry assembly or not, it can request the current process the way Solution 1 tells you. It cannot give you anything unless you somehow communicate with other processes or some inter-process facilities, something collectively known as "IPC", and even then you would not need the ID. You can get more help if your explain your ultimate goals.

—SA


我只是不得不道歉,我没有说清楚。

我正在开发与主程序并行运行的插件。我没有办法获得打开插件的主应用程序的进程ID。

问题是主应用程序可能有多个实例正在运行。
I just have to apologize, I didn't make myself clear.
I am developing addons which runs in parallel with the main program. and I don't have any way to get the process ID of the main application that opened the addon.
The problem is that there can be multiple instances of the main application running.


这篇关于如何在加载的dll中找到进程ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆