C#调C语言DLL ,不能返回嵌套结构体的值

asdfg48_ 2014-12-05 11:09:20
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]; 的值
大家看看应该怎样封装和接受嵌套结构体中的值
...全文
164 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧