如何将 DLL 作为本地服务器加载
我真的需要帮助...
我已经用 IDL 实现了一个 COM 组件(即 A.dll),还为该组件编写了一个包装 DLL(B.dll)。我已经实现了 DLL“A”所需的导出函数,并将其注册到“regsvr32.exe”。
问题是我有 3 个 EXE 文件使用 B.dll 访问 A.dll 的方法。但是,我无法为 A.dll 创建本地服务器,因此每个 EXE 都会加载新的 A.dll 和 B.dll。我只想加载A.dll一次,并且需要在B.dll中实现此功能。最后的声明也可供讨论。
但是,我无法找到有关此问题的任何有用的示例或资源。任何帮助将不胜感激,提前致谢。
I really need help...
I have implemented a COM component (i.e A.dll) with IDL, also coded a wrapper DLL (B.dll) for that component. I have implemented required export functions for DLL "A" and registered it with "regsvr32.exe".
Problem is that I have 3 EXE files that uses B.dll to access methods of A.dll. But, I could not manage to create a local server for A.dll, therefore every EXE loads a new A.dll and B.dll. I want to load A.dll only once, and need to realize this functionality in B.dll. Last statement is open for discussion also.
However, I could not manage to find any useful example or resource regarding this problem. Any help will be appreciated, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由 COM 介导的 DLL 称为进程内服务器。这表明了你的问题:它总是被映射到其客户端的内存空间,就像任何其他 DLL 一样。同样,它加载的任何 DLL 将被映射到原始进程中。从您的问题中并不清楚为什么您不想使用 DLL。如果是为了节省资源那就考虑只复制数据;该代码只会加载一次。如果是因为您希望它们共享数据,那么请考虑使用共享内存。如果您确实希望所有三个 .exe 都由一个实例提供服务,那么您需要的是一个 COM 本地服务器,它将由 .exe 而不是 .dll 实现。
A DLL mediated by COM is known as an in-process server. Which suggests your problem: it will always be mapped into the memory space of its clients, just like any other DLL. Similarly any DLLs it loads will be mapped into the original process. It is not clear from your question why you don't want to use a DLL. If it is to save resources then consider that only data will be duplicated; the code will only be loaded once. If it is because you want them to share data, then consider using shared memory. If you really want all three .exe's to be served by an instance then what you need is a COM local server, which will be implemented by an .exe, not a .dll.
不存在“创建本地服务器”这样的事情。进程内服务器必须加载到每个消费者进程中,没有办法解决这个问题 - 每个消费者都是一个单独的进程,因此它有自己的代码和数据副本。
为了让单个进程为所有使用者执行 COM 服务器代码,您必须创建一个进程外服务器。要执行后者,您可以重新设计 COM 服务器或尝试使用 COM+ 服务器应用程序。通过这种方式,您可以有一个单独的进程来运行多个使用者可以连接的 COM 服务器代码。
There's no such thing as "create a local server". In-proc server has to be loaded into each consumer process, there's no way around that - each consumer is a separate process, so it has its own copy of code and data.
In order to have a single process executing COM server code for all of the consumers you have to create an out-proc server. To do the latter you can either reengineer your COM server or try to use COM+ server application. This way you can have a separate process running the COM server code several consumers can connect to.