110,533
社区成员
发帖
与我相关
我的任务
分享
int size = Marshal.SizeOf(typedef(TagAttr)) ;
IntPtr attrInput = Mashal.AllocHGlobal(count*size);
DBPT.GetTagsAttributeWithPtr(nHandle,count,out errors,ids, attrInput);
for(int i = 0;i< count;i++)
{
IntPtr ptr = (IntPtr)((UInt32)attrInput + i* size);
tagsArray[i] = (TagAttr)Mashal.PtrToStructure(ptr,typeof(TagAttr));
}
Marshal.FreeHGlobal(attrInput);
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string[] szFontName;
不能用string[],char[]数组对应的string[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct PassOutput
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string szFontName;
public int dwFontAttrib;
}
//得到结构体的大小
int size = Marshal.SizeOf(fontRecord);
//创建byte数组
byte[] _bytes = new byte[size];
//分配结构体大小的内存空间
IntPtr indata = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(fontRecord, indata, false);