Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.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
从c++;c#dll的代码_C#_Visual C++ - Fatal编程技术网

从c++;c#dll的代码

从c++;c#dll的代码,c#,visual-c++,C#,Visual C++,我试图将一个字符串(图像文件路径)传递给c#dll接口。我发现以下运行时错误, “未处理的异常:System.AccessViolationException:尝试读取或写入受保护的内存。这通常表示其他内存已损坏。” 在System.String.wstrcpy处(char*dmem、char*smem、Int32 charCount) at System.String.CtorCharPtrStartLength(char*ptr,Int32 startIndex,Int32 length)

我试图将一个字符串(图像文件路径)传递给c#dll接口。我发现以下运行时错误, “未处理的异常:System.AccessViolationException:尝试读取或写入受保护的内存。这通常表示其他内存已损坏。”

在System.String.wstrcpy处(char*dmem、char*smem、Int32 charCount)

at System.String.CtorCharPtrStartLength(char*ptr,Int32 startIndex,Int32 length)

位于System.StubHelpers.BSTRMarshaler.ConvertToManaged(IntPtr bstr)”

C++代码: Char img=“filepath”; 将字符类型转换为无符号短*并传递到C#dll接口

C#dll接口:
采样接口(字符串str)

> P>因为您将字符串从C++传递到C语言DLL。我建议将该字符串作为BSTR传递


因为这两种语言是不同的。

“将字符类型转换为无符号短字符”*。。。。呃。。。
char
实际上不是
unsigned short*
那么您希望类型转换实现什么?字符串编码为Unicode或ANSI?@Roger Rowland如果我不将类型转换为unsigned short*编译器将给出错误。@Salvatore如何检查字符串编码为Unicode或ANSI?我真正想做的是:我想传递文件路径作为C++ C++语言接口的参数,请给出示例代码片段,对我有很大帮助。