[英]Passing std::string as parameter from one DLL to another DLL throwing access violation error
The application has many C++ compiled DLLs, each exposing many C type interfaces. 该应用程序具有许多C ++编译的DLL,每个DLL都公开许多C类型的接口。 The application has some std::string type configuration variables which needs to be used in the DLL interface logic.
该应用程序具有一些std :: string类型的配置变量,这些变量需要在DLL接口逻辑中使用。 While passing this std::string type parameters to these DLLs, "0xC0000005: Access violation executing location" has thrown.
在将此std :: string类型参数传递给这些DLL时,抛出了“ 0xC0000005:访问冲突执行位置”。 Is this something related to VS project settings for DLL projects?
这与DLL项目的VS项目设置有关吗? Kindly clarify.
请澄清。
You probably won't make them to work easily. 您可能不会使它们轻松工作。
std::string
may not be compatible between different compilations from different libraries. std::string
在不同库的不同编译之间可能不兼容。
When you say "The application has many C++ compiled DLLs", very likely you're in this scenario: 当您说“应用程序具有许多C ++编译的DLL”时,很可能您处于这种情况:
Library A: 库A:
// STL
class std::string
{
... under the hood implementation of std::string (version A)
};
// Library code
std::string someFunctionInA();
Library B: 图书馆B:
// STL
class std::string
{
... under the hood implementation of std::string (version B)
};
// Library code
void someFunctionInB(const std::string& myString);
The crash program: 崩溃程序:
std::string stringFromA = someFunctionInA();
someFunctionInB(stringFromA);
Got it? 得到它了? You have 2 versions of
std::string
and you program compiles because you're using the same headers during the compilations of your program... but in runtime, they are expecting 2 different types. 您有2个版本的
std::string
并进行了程序编译,因为在程序编译期间使用的是相同的标头...但是在运行时,它们期望使用2种不同的类型。
Size of the objects, order of data and simply the allocators may not match... and it will crash! 对象的大小,数据的顺序以及分配器可能不匹配...它将崩溃!
How to resolve: 解决方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.