Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用STD:String的C++ DLL函数_C++_Dllimport - Fatal编程技术网

使用STD:String的C++ DLL函数

使用STD:String的C++ DLL函数,c++,dllimport,C++,Dllimport,可能重复: 有没有一种方法将C++从STD:string转换成C String?我从C++ DLL调用函数,它以STD:string作为输入。有没有一个简单的方法可以做到这一点 C: C++: DLL不应在其接口中使用std::string。请看,在不同的编程语言之间共享内置的复杂数据类型从来都不是一个好主意,无论它们多么相似,因为您不知道数据类型是如何在内部构建的。更好的方法是导出您已知的内容,在此上下文中,以null结尾的字符*应该可以完成这项工作。请注意,C/C++中的BOOL应该使用默

可能重复:

有没有一种方法将C++从STD:string转换成C String?我从C++ DLL调用函数,它以STD:string作为输入。有没有一个简单的方法可以做到这一点

C:

C++:


DLL不应在其接口中使用std::string。请看,在不同的编程语言之间共享内置的复杂数据类型从来都不是一个好主意,无论它们多么相似,因为您不知道数据类型是如何在内部构建的。更好的方法是导出您已知的内容,在此上下文中,以null结尾的字符*应该可以完成这项工作。请注意,C/C++中的BOOL应该使用默认封送处理程序进行封送,而不是使用UnmanagedType.I1-必须将C++的BOOL封送为I1或U1。
[DllImport(@"MyDLL.dll")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool myFunction([In, Out]string input);
extern "C" __declspec(dllexport) BOOL __stdcall myFunction(const std::string& input)
{
  //Code is here
}