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); /*释放空间*/
string ps="内容";
GCHandle C_ps = GCHandle.Alloc(ps, GCHandleType.Pinned);
read_pump_status(nPumpPort,C_ps.AddrOfPinnedObject());
C_ps.Free();
没有测试环境,凭印象写的