元帅C ++"串"在C#中的P / Invoke类元帅、QUOT、Invoke

由网友(活雷疯!)分享简介:我在定义一个本地DLL中的函数如下:I have a function in a native DLL defined as follows:#include void SetPath(string path);我试图把这个微软的P /调用互操作助理,但它闷死在字符串级(我认为这是从MFC?)。...

我在定义一个本地DLL中的函数如下:

I have a function in a native DLL defined as follows:

#include <string>
void SetPath(string path);

我试图把这个微软的P /调用互操作助理,但它闷死在字符串级(我认为这是从MFC?)。

I tried to put this in Microsoft's P/Invoke Interop Assistant, but it chokes on the "string" class (which I think is from MFC?).

我试图封送它作为各种不同类型的(C#字符串和char [],byte []的),但每次我要么得到一个NotSupportedException异常或本地大会异常(这取决于封送我试过)。

I have tried marshaling it as a variety of different types (C# String, char[], byte[]) but every time I either get a NotSupportedException or a Native Assembly Exception (depending on what marshaling I tried).

由于有人曾经做过本地/管理的互操作,其中本地字符串类用于?有什么办法元帅呢?我是不是有写我自己的封送拆?

As anyone ever done Native/Managed Interop where the native string class is used? Is there any way to Marshal this? Am I going to have to write my own Marshaler?

推荐答案

看起来你试图使用C ++标准库的string类。我怀疑,这将是很容易元帅。最好坚持使用一个char *元帅为StringBuilder的。这就是我通常做。你必须添加一个包装器,生成的C ++字符串为您服务。

Looks like you're trying to use the C++ standard library string class. I doubt that will be easy to Marshal. Better to stick with a char * and Marshal as StringBuilder. That's what I usually do. You'll have to add a wrapper that generates the C++ string for you.

阅读全文

相关推荐

最新文章