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 ++函数?
答案 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 );