日期:2014-05-17  浏览次数:20736 次

C++转换C#问题
void CALLBACK MessageCallback(LONG lCommand, NET_DVR_ALARMER *pAlarmer, char *pAlarmInfo, DWORD dwBufLen, void* pUser)
{
  int i;
  switch(lCommand) 
  {       
  case COMM_ALARM:
      {
          NET_DVR_ALARMINFO struAlarmInfo;
          memcpy(&struAlarmInfo, pAlarmInfo, sizeof(NET_DVR_ALARMINFO));
          switch (struAlarmInfo.dwAlarmType)
          {
          case 3: //移动侦测报警
               for (i=0; i<16; i++)   //#define MAX_CHANNUM   16  //最大通道数
               {
                   if (struAlarmInfo.dwChannel[i] == 1)
                   {
                       printf("发生移动侦测报警的通道号 %d\n", i+1);
                   }
               }       
          break;
          default:
          break;
          }
       }
  break;
  default:
  break;
  }
}


请教:1、以上回调函数的参数pAlarmInfo转换成C#是否为string类型?
2、若该参数为string,则memcpy(&struAlarmInfo, pAlarmInfo, sizeof(NET_DVR_ALARMINFO))在C#中该如何处理?

------解决方案--------------------
string 和 char 数组 应该都可以   
memcpy 就是赋值 
------解决方案--------------------
转成C#的不能设置成string, 因为那个看起来是传了一个字节流进来,然后需要转成结构体。翻译成IntPtr就行。然后直接用Marshal.PtrToStructure就可以了