[英]C++ Plug-in Version Checking via Function Export
I have two DLLs, Core
and Extension
. 我有两个DLL,
Core
和Extension
。 Extension
implicitly links Core
(using Core.lib). Extension
隐式链接Core
(使用Core.lib)。 Extension
is intended to be a plug-in (explicitly linked) into an executable which also implicitly links Core
. Extension
旨在作为一个插件(明确链接)到一个可执行文件中,该可执行文件还隐式链接Core
。
Core
declares a function which is exported in Core.dll ( extern "C" __declspec(dllexport) int GetCoreVersion()
), which I would also like to export in Extension.dll. Core
声明了一个在Core.dll中导出的函数( extern "C" __declspec(dllexport) int GetCoreVersion()
),我也想在Extension.dll中导出该函数。
The intended purpose is to compare versions--I want to be able to ensure that the plug-in (Extension) was linked against the same version of Core.dll as the executable. 预期目的是比较版本-我希望能够确保将插件(Extension)链接到与可执行文件相同的Core.dll版本。 This check would be performed in the executable, as it explicitly links Extension.dll (via
LoadLibrary
and GetProcAddress
). 该检查将在可执行文件中执行,因为它显式链接了Extension.dll(通过
LoadLibrary
和GetProcAddress
)。 Is there a better way? 有没有更好的办法?
I added the following to Extension, which causes the GetCoreVersion
symbol to be exported: 我在扩展中添加了以下内容,这导致导出
GetCoreVersion
符号:
#pragma comment(linker, "/export:_GetCoreVersion");
The executable is now able to find the function (via GetProcAddress("GetCoreVersion")
). 可执行文件现在可以找到该函数(通过
GetProcAddress("GetCoreVersion")
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.