如何在不再次加载的情况下在同一进程加载的两个 DLL 之间进行通信?
How communicate between two DLLs loaded by same process without loading them again?
我想在应用程序中的两个插件之间进行通信。
这两个插件都是 C++ COM DLL。我们称它们为 DLL1 和 DLL2。
在 DLL1 中,我创建了一个加载 COM DLL 的 COM class 实例。
从 DLL2,我可以创建该 COM class 的类似实例,它可能会再次加载该 COM DLL。
基本上,我不想再次从 DLL2 加载那个 COM DLL 并以某种方式获取这个已经由 DLL1 加载的 COM DLL 的句柄。
我可以从 DLL2 调用 COM DLL(由 DLL1 加载)中存在的函数而不再次加载它吗?
这里的约束是,我不想从 DLL2 加载 COM DLL。它将由 DLL1 加载,我只想从 DLL2 执行该 COM DLL 函数。
来自LoadLibrary
documentation:
The system maintains a per-process reference count on all loaded modules. Calling LoadLibrary increments the reference count. Calling the FreeLibrary or FreeLibraryAndExitThread function decrements the reference count. The system unloads a module when its reference count reaches zero or when the process terminates (regardless of the reference count).
和
If the specified module is a DLL that is not already loaded for the calling process, the system calls the DLL's DllMain function with the DLL_PROCESS_ATTACH value. If DllMain returns TRUE, LoadLibrary returns a handle to the module. If DllMain returns FALSE, the system unloads the DLL from the process address space and LoadLibrary returns NULL.
因此在同一进程中两次调用LoadLibrary("XXX.dll")
只会导致加载库一次,第二次调用应该返回相同的模块句柄。
我想在应用程序中的两个插件之间进行通信。 这两个插件都是 C++ COM DLL。我们称它们为 DLL1 和 DLL2。
在 DLL1 中,我创建了一个加载 COM DLL 的 COM class 实例。 从 DLL2,我可以创建该 COM class 的类似实例,它可能会再次加载该 COM DLL。
基本上,我不想再次从 DLL2 加载那个 COM DLL 并以某种方式获取这个已经由 DLL1 加载的 COM DLL 的句柄。 我可以从 DLL2 调用 COM DLL(由 DLL1 加载)中存在的函数而不再次加载它吗?
这里的约束是,我不想从 DLL2 加载 COM DLL。它将由 DLL1 加载,我只想从 DLL2 执行该 COM DLL 函数。
来自LoadLibrary
documentation:
The system maintains a per-process reference count on all loaded modules. Calling LoadLibrary increments the reference count. Calling the FreeLibrary or FreeLibraryAndExitThread function decrements the reference count. The system unloads a module when its reference count reaches zero or when the process terminates (regardless of the reference count).
和
If the specified module is a DLL that is not already loaded for the calling process, the system calls the DLL's DllMain function with the DLL_PROCESS_ATTACH value. If DllMain returns TRUE, LoadLibrary returns a handle to the module. If DllMain returns FALSE, the system unloads the DLL from the process address space and LoadLibrary returns NULL.
因此在同一进程中两次调用LoadLibrary("XXX.dll")
只会导致加载库一次,第二次调用应该返回相同的模块句柄。