标准::字符串在C#中? [英] std::string in C#?

查看:127
本文介绍了标准::字符串在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这个问题是我的C ++函数里面,但我想这

I thought the problem is inside my C++ function,but I tried this

C ++函数在C ++中的dll:

C++ Function in C++ dll:

bool __declspec( dllexport ) OpenA(std::string file)
{
return true;
}

C#code:

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?

如果我删除的std ::字符串参数,它的伟大工程,但与标准::字符串它不工作。

If I remove the std::string parameter,it works great,but with std::string it doesnt work.

推荐答案

标准::字符串和C#字符串不相互兼容。据我知道C#字符串对应路过的char * wchar_t的* 在C ++中尽可能互操作关注。

其中的一个原因,这是可以有许多不同的实现来为std :: string和C#不能假设你使用任何特定的。

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.

这篇关于标准::字符串在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆