C#调C语言DLL ,不能返回嵌套结构体的值
C语言:
typedef struct DecisionTreeNode{
int keynum;
char SelectedAttributeName[Max_Attribute_Name_Length];
char AttributeValue[Max_Attribute_Name_Length];
int Record_Marker[Max_Record_Number];
int Attribute_Marker[Max_Attribute_Number];
struct DecisionTreeNode *ptr[Max_Discrete_Value_Number];
}DecisionTreeNode, *DecisionTree;
extern"C"_declspec(dllexport)DecisionTree C4_5_main(DecisionTree Tree)
{
/////////////////////////////////Coding..........................
return Tree;
}
C# :
[StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Ansi)]
public struct DecisionTreeNode
{
public int keynum;
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 10)]
public string SelectedAttributeName;
/// char[30]
[System.Runtime.InteropServices.MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 10)]
public string AttributeValue;
/// int[800]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 800, ArraySubType = System.Runtime.InteropServices.UnmanagedType.I4)]
public int[] Record_Marker;
/// int[10]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = System.Runtime.InteropServices.UnmanagedType.I4)]
public int[] Attribute_Marker;
/// DecisionTreeNode*[5]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 5, ArraySubType = System.Runtime.InteropServices.UnmanagedType.SysUInt)]
public System.IntPtr[] ptr;
//public DecisionTreeNode[] ptr1;
}
[DllImport("C4.5_DLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
private extern static IntPtr C4_5_main();
unsafe static void Main(string[] args)
{
IntPtr ptr = C4_5_main();
DecisionTreeNode tree = (DecisionTreeNode)Marshal.PtrToStructure(ptr, typeof(DecisionTreeNode));
}
现在就是 public System.IntPtr[] ptr;中不能得到struct DecisionTreeNode *ptr[Max_Discrete_Value_Number]; 的值
大家看看应该怎样封装和接受嵌套结构体中的值