C#调用C++写的dll如何获得结构体的指针
现在有两个结构体:
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct GroupProfile
{
/// Profile*
public IntPtr profile;
/// int
public int profileNum;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct tagProfile
{
/// char[512]
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 512)]
public string fileName;
/// char[512]
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 512)]
public string name;
/// int
public int langCount;
/// char*[10]
/// 不同语言的名字
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.SysUInt)]
public System.IntPtr[] langName;
/// char*[10]
/// Profile 的显示名
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.SysUInt)]
public System.IntPtr[] displayName;
/// char*[10]
/// 对Profile的描述
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.SysUInt)]
public System.IntPtr[] desc;
/// char[128]
/// 输出格式
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 128)]
public string format;
/// char[128]
/// 输出格式的扩展名
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 128)]
public string extName;
/// int
/// 是否为系统定义
public int isSysProfile;
/// int
public int type;
/// int
/// 设备类型
public int device;
/// int
public int groupId;
/// char*[10]
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.SysUInt)]
public System.IntPtr[] groupName;
/// ConfigItem*
public System.IntPtr configItems;
/// int
public int configItemsNum;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct tagConfigItem
{
/// char[512]
/// configItem的名字,也是唯一标示
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 512)]
public string name;
/// char[128]
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 128)]
public string group;
/// int
public int readyOnly;
/// int
/// configItem的控件类型
public int displayType;
/// int
public int valueType;
/// char*[10]
///
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.SysUInt)]
public System.IntPtr[] label;
/// char*[10]
/// 对configItem的描述
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.SysUInt)]
public System.IntPtr[] desc;
/// ListItem*
public System.IntPtr listItems;
/// int
public int listItemNum;
/// int
public int defaultListIndex;
/// char[512]
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 512)]
public string defaultValue;
/// Profile*
public System.IntPtr profile;
}
C++函数为DLL_DECLEARTYPE_PRASEXML int DLL_CALLTYPE praseXMLFolder(char *xmlFolder,GroupProfile *groupProfile);
这个函数的主要作用是,循环便利XmlFolder路径下的所有xml,我这里的文件下有187个xml目录,所以这个函数执行成功后,返回的groupProfile的profileNum是187,groupProfile的profile是个数组,存的是187个xml的结构体tabProfile(上面定义的)
我在C#中这样定义的函数
[DllImport("ttsProfileDll.dll", EntryPoint = "_praseXMLFolder@8", ExactSpelling = false, SetLastError = true)]
public static extern int praseXMLFolder(string xmlFolder, ref UtilityHelper.GroupProfile gprofile);
不知道我这样定义是否正确,,我现在照这种方法能取出一定的值
UtilityHelper.GroupProfile gProfile = new UtilityHelper.GroupProfile();
int s = XmlHelper.praseXMLFolder(@"..\..\profile", ref gProfile);
这样取出的profileNum是187,但是groupProfile的profile确只有一个,我像知道如何取得这个groupProfile的profile数组,也就是结构体数组的值,,,在网上找了很多的资料,都有点不是很明白,我没有做过指针方面的东西,希望各位高手指点指点。。。。