当前位置:编程学习 > C#/ASP.NET >>

请教怎样封送自定义结构数组

函数原型:
BOOL GetData(void* pCommand, void* pDataBuffer, int nSize)
功能:把*pCommand所指向的数据解析到*pDataBuffer中去
参数:void* pCommand:无类型指针
      void* pDataBuffer:无类型指针,接收数据缓存区
      int nSize:接收数据的大小
===============================================================
在c#中定义如下:
//结构体
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]
public struct PosRecord
{
public int nCardID;
public int nExpenditure;
public int nBalance;
public int nTotalTimes;
public int nOperatorID;
public int nYear, nMonth, nDay, nHour, nMinute, nSecond;
public bool bNormal;
public bool bCancel;
public bool bReload;
public int nDMAdr;
}
//声明函数
[DllImport(ICDMproc, SetLastError = true, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
public static extern bool GetData(void* pCommand, ref PosRecord pDataBuffer, int nSize);
//调用
PosRecord posRecord = new PosRecord();
GetData(m_pCommand, ref posRecord, 60);
=============================================================
以上代码在只返回一个结构体时运行和获取结果没有任何问题,但要是返回是2个以上结构体时,就不知到怎么处理!尝试修改如下不能成功.
//声明
[DllImport(ICDMproc, SetLastError = true, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
public static extern bool GetData(void* pCommand, ref PosRecord[] pDataBuffer, int nSize);
//调用
PosRecord[] posRecord = new PosRecord[2]();
GetData(m_pCommand, ref posRecord, 120);
========================================================================
看看那个高手能帮忙指点下,呵呵,分数好商量!!!

--------------------编程问答-------------------- up
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,