简体   繁体   English

基于Visual Studio 2005构建的C ++ Exe是否可以动态加载基于Visual Studio 2015构建的DLL

[英]Can a C++ Exe built on MS visual studio 2005 load a DLL dynamically which is built on visual studio 2015

Currently i have an third party visual studio application which was built on Visual studio 2005 and this application uses one of our DLL through the plugin framework. 目前,我有一个基于Visual Studio 2005构建的第三方Visual Studio应用程序,该应用程序通过插件框架使用我们的DLL之一。 Recently this DLL(Client) was built on Visual studio 2015, will this cause the third party application to crash? 最近,这个DLL(Client)建立在Visual Studio 2015上,这会导致第三方应用程序崩溃吗?

Can someone explain how the run time of visual c++ works in such cases 有人可以解释在这种情况下Visual c ++的运行时如何工作

It's actually not a runtime. 它实际上不是运行时。 Really during dll load there is no difference if the DLL was built in VS2015 or VS2005 if interfaces match. 实际上,如果接口匹配,则在DLL加载期间,如果DLL是在VS2015或VS2005中构建的,则没有区别。

They will match however only if the library has C-like or COM-like interface. 但是只有在库具有类似C或类似COM的接口时,它们才会匹配。

Also as already mentioned in comments, the CRT libraries are not compatible, but there can be a solution: 另外,正如评论中已经提到的,CRT库不兼容,但是可以有一个解决方案:

Any DLL can be linked against different CRT versions, it's what is specified with /MT /MD /MTd so on options https://msdn.microsoft.com/en-us/library/2kzt1wy3(v=vs.140).aspx If your library has static linkage with CRT (ie /MT or /MTd) it will not collide with an external environment. 任何DLL都可以链接到不同的CRT版本,这是使用/ MT / MD / MTd指定的,因此在选项https://msdn.microsoft.com/zh-cn/library/2kzt1wy3(v=vs.140).aspx如果您的库与CRT具有静态链接(即/ MT或/ MTd),则不会与外部环境发生冲突。 However to succeed you library has no right to free any memory gotten from the environment, neither that environment is allowed to free the memory obtained from you library. 但是,要成功,您的库无权释放从环境中获取的任何内存,也不允许该环境释放从您的库中获取的内存。 It usually means following the rule: the library which allocated memory has to free it. 这通常意味着遵循规则:分配内存的库必须释放它。 As a workaround you can use HeapAlloc function. 解决方法是使用HeapAlloc函数。

Additionally it's worth to mention that you have no any chance to succeed in case you use in interfaces any of STL containers. 另外值得一提的是,如果您在接口中使用任何STL容器,则没有任何成功的机会。 (std::vector, map, set so on) because they were changed drastically since 2005 year. (std :: vector,map等),因为它们自2005年以来发生了巨大变化。

In case you have a cryptic linker errors which says something about CRT incompatibilities you can try def files to precisely specify what functions and variables are exported. 如果您有一个隐秘的链接器错误,该错误说明CRT不兼容,您可以尝试使用def文件来精确指定要导出的函数和变量。 You better to have C interface (you can use extern "C" construct to ensure symbol mangling doesn't add more troubles) 最好具有C接口(可以使用extern“ C”构造来确保符号修饰不会增加麻烦)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Visual Studio 2010 C++ 项目中使用 MinGW 构建的 dll - Using MinGW built dll in a Visual Studio 2010 C++ project 可以将使用Visual Studio 2008编译的C ++ dll与Visual Studio 2005一起使用吗? - Can a C++ dll compiled using Visual Studio 2008 be used with Visual Studio 2005? Visual Studio C ++将.exe + .dll转换为.exe - Visual Studio C++ turn .exe +.dll into only .exe MS Visual Studio 2005 C ++异常处理 - MS Visual Studio 2005 C++ exception handling 用于CLI构建的嵌入式C ++的Visual Studio自定义构建定义 - Visual Studio custom build definitions for CLI built embedded C++ 构建时如何在Visual Studio C ++中加载文件 - How files will be loaded in Visual Studio C++ when built 在 Visual Studio Code 中调试使用 makefile 构建的 c++ - Debugging c++ built with a makefile in Visual Studio Code 想知道较低版本的Visual Studio是否可以使用使用较高版本的Visual Studio构建的dll? - Wondering if the lower version of visual studio can use the dll built using higher version of visual studio? visual Studio 2015 c ++将独立的dll文件添加到项目 - visual studio 2015 c++ add a standalone dll file to a project 将Visual Studio C ++ dll项目转换为exe - convert visual studio C++ dll project to exe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM