从 v100 调用时在平台工具集 v140 DLL 上写入访问冲突
Access violation writing on platform toolset v140 DLL when call from v100
我有一个用 VS2015 编写的 DLL,平台工具集:Visual Studio 2015 (v140)。
此 DLL 包含以下功能:
std::string GetUserPoints(std::string ownerid);
我在 visual studio 2010 年创建了一个 win32 控制台应用程序,并尝试调用此 "GetUserPoints" 函数!
当 GetUserPoints 瞄准 return 字符串值时,我遇到运行时访问冲突。
我尝试将此 GetUserPoints 更改为:
int GetUserPoints(std::string ownerid, char*& output)
{
if (l_RestLowLevel != NULL) {
std::string str = utility::conversions::to_utf8string(l_RestLowLevel->GetUserCameraPoints(utility::conversions::to_string_t(ownerid)));
// Dynamically allocate memory for the returned string, +1 for terminating NULL
output = new char[str.length()+1];
// Copy source string in dynamically allocated string buffer
strncpy_s(output, str.length() + 1, str.c_str(), str.length());
return str.size();
}
return 0;
}
但是我得到了一个运行时 "Access violation writing" 异常:
output = new char[str.length()+1];
所有版本的 Visual C++ 都有自己的标准库实现,它们不一定相同,实际上它们很可能不同。
由于不兼容,建议不要在 DLL 接口中指定标准库元素。
在您的程序和/或 Dll 的内部,您可以毫无问题地使用它们。但是当彼此交互时,你必须就实现达成一致。
我有一个用 VS2015 编写的 DLL,平台工具集:Visual Studio 2015 (v140)。 此 DLL 包含以下功能:
std::string GetUserPoints(std::string ownerid);
我在 visual studio 2010 年创建了一个 win32 控制台应用程序,并尝试调用此 "GetUserPoints" 函数!
当 GetUserPoints 瞄准 return 字符串值时,我遇到运行时访问冲突。
我尝试将此 GetUserPoints 更改为:
int GetUserPoints(std::string ownerid, char*& output)
{
if (l_RestLowLevel != NULL) {
std::string str = utility::conversions::to_utf8string(l_RestLowLevel->GetUserCameraPoints(utility::conversions::to_string_t(ownerid)));
// Dynamically allocate memory for the returned string, +1 for terminating NULL
output = new char[str.length()+1];
// Copy source string in dynamically allocated string buffer
strncpy_s(output, str.length() + 1, str.c_str(), str.length());
return str.size();
}
return 0;
}
但是我得到了一个运行时 "Access violation writing" 异常:
output = new char[str.length()+1];
所有版本的 Visual C++ 都有自己的标准库实现,它们不一定相同,实际上它们很可能不同。
由于不兼容,建议不要在 DLL 接口中指定标准库元素。
在您的程序和/或 Dll 的内部,您可以毫无问题地使用它们。但是当彼此交互时,你必须就实现达成一致。