0

I need to call a C++ library from a C# program, I have a method whose signature looks like:

int __stdcall meythodName(const char *c, struct TheirStruct[] s1, struct TheirStruct[] s2)

all parameters are output parameters.

I'm trying to call this method like this:

[DllImport("theirlib.dll", CallingConvention = CallingConvention.StdCall)]
extern static int meythodName(ref string c, ref TheirStruct[] s1, ref TheirStruct[] s2);

With TheirStruct being like:

[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 13)]
public class TheirStruct
{
   public int i;  
   public int j;
   [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5)]
   public string s;
}

TheirStruct (PACKED and 13 byte in size) is described in dll manual as:

#define LEN 5
#define SIZE 50

struct TheirStruct 
{
    char c[LEN]; 
    int i;                   
    int j;                   
};

When I try to call this method my application simply terminates without giving me an error code, can you give me some explanations about this issue?

4

1 回答 1

0

成立!!!

我只需要在他们的结构声明中将“类”更改为“结构”,删除方法调用中的 di“ref”关键字并相应地设置 [In]/[Out]。

很简单,希望对你有帮助!!

于 2013-09-23T10:47:34.203 回答