如何使用C#中的指针结构参数调用C ++函数?

时间:2015-02-06 14:00:08

标签: c# c++ vb.net

C ++函数在" c ++。dll"

中定义
FunctionName int GetDevice(VB_Device_Info* params){ do something...}

typedef struct
{
  char Name[10];
   int nPort;
}VB_Device_Info;

我试图调用此函数并在VB中运行良好

Public Structure VB_Struc   
   Public Name As String   
   Public nPort As Integer  
End Structure
<DllImport("c++.dll")> 
Public Shared Function FunctionName(<[In](), Out()> ByVal StructArray() As VB_Struct) As Integer
End Function

如何在C#中定义这个C ++函数?

1 个答案:

答案 0 :(得分:0)

你可以尝试一下吗?

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)] struct VB_Device_Info{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=10)] public String Name; int nPort; } [DllImport("c++.dll"] static extern int GetDevice(ref VB_Device_Info );