【发布时间】:2013-12-27 09:27:55
【问题描述】:
目前我正在使用 C++ 制作一个 dll 函数。之后,我使用DllImport 将此 dll 导入到我的 C# 项目中。在我的 C++ 项目中,我在第一次构建过程中收到警告 C4190。
警告 C4190: 'abc' 指定了 C 链接,但返回 UDT'std::basic_string' 与 C 不兼容
我目前的代码如下:
extern "C"
{
__declspec(dllexport) std::string abc(std::string targetFile)
{
return somestring;
}
}
【问题讨论】:
-
它告诉你不能对 C 使用 STL 类型。
-
我不认为 std::string 和 C# 字符串混合得很好。 (如果可能的话,我愿意接受这方面的教育。)。相反,只需 export 导出一个使用 char* 作为参数的 C 函数。在网络上搜索“P/Invoke”,您会发现一些有关如何执行此操作的建议。
-
欢迎来到 StackOverFlow.. :)