以下是我对该函数的 C++ 声明:
unsigned moduleDescription (unsigned modulnumber, char * const name, t_c_pindescription * const p_inputs, t_c_pindescription * const p_outputs, t_c_pindescription * const p_intern);
以下是我的 C++ 结构定义:
#pragma pack(push,4)
typedef struct
{
char name[256];
char dim[64];
enum SigTypetype;
} t_c_pindescription;
typdef enum SigType
{
T_ANALOG = 1,
T_BINARY = 2,
T_OPTIONAL
};
#pragma pack(pop)
以下是我的 C# 客户端代码:
public class Program
{
[StructLayoutAttribute(LayoutKind.Sequential,CharSet = CharSet.Unicode)]
public struct t_c_pindescription
{
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 256)]
public string pinname;
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 64)]
public string Dimension;
public SigType mType;
}
public enumSigType
{
T_ANALOG = 1,
T_BINARY = 2,
T_OPTIONAL = 4,
}
[System.Runtime.InteropServices.DllImportAttribute("abc.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "moduleDescription",CharSet=CharSet.Ansi)]
public static extern int moduleDescription(int modulnumber,StringBuilder name,[Out] t_c_pindescription[] ppsainputs, [Out] t_c_pindescription[] ppsaoutputs, [Out] t_c_pindescription[] ppsaintern);
public static void Main(string[] args)
{
t_c_pindescription[] inputdesarray = new t_c_pindescription[200];
t_c_pindescription[] outputdesarray = new t_c_pindescription[200];
t_c_pindescription[] interndesarray = new t _c_pindescription[200];
StringBuilder sb = newStringBuilder();
for(int i = 0; i < 10; i++)
{
moduleDescription(i, sb, inputdesarray, outputdesarray, interndesarray);
}
}
}
在这里,我无法获取我的结构数组值,即 inputdesarray、outputdesarray 和 interndesarray 中的值。