更新时间:2023-11-14 15:49:40
std :: string和c#string彼此不兼容。据我所知,c#字符串对应于在c ++中传递 c> char * 或 wchar_t *
。
其中一个原因是std :: string可能有许多不同的实现,而c#不能假定你使用任何特定的。
I thought the problem is inside my C++ function,but I tried this
C++ Function in C++ dll:
bool __declspec( dllexport ) OpenA(std::string file)
{
return true;
}
C# code:
[DllImport("pk2.dll")]
public static extern bool OpenA(string path);
if (OpenA(@"E:\asdasd\"))
I get an exception that the memory is corrupt,why?
If I remove the std::string parameter,it works great,but with std::string it doesnt work.
std::string and c# string are not compatible with each other. As far as I know the c# string corresponds to passing char*
or wchar_t*
in c++ as far as interop is concerned.
One of the reasons for this is that There can be many different implementations to std::string and c# can't assume that you're using any particular one.