SDK指针存在问题-将C ++转换为Delphi

时间:2019-01-16 14:44:28

标签: c++ delphi pointers sdk hikvision

我正在努力使用HikVision SDK,试图使其在Delphi中运行。 C ++中有一些示例,但是在转换为Delphi时我一直遇到指针问题。直到我获得正确的车牌号为止,此刻代码似乎可以正常工作。
这是否正确等效:BYTE * pBuffer-> PByte?
如何从pBuffer中提取图片?

C ++代码:

typedef struct tagNET_ITS_PICTURE_INFO
{
    DWORD   dwDataLen;            //Media data length
    BYTE    byType;                
    BYTE    byAbsTime[32];
    NET_VCA_RECT   struPlateRect;
    BYTE    *pBuffer;              //Data pointer
    DWORD   dwUTCTime;
    //...
}NET_ITS_PICTURE_INFO, *LPNET_ITS_PICTURE_INFO;


typedef struct tagNET_ITS_PLATE_RESULT
{
    //...
    NET_DVR_PLATE_INFO  struPlateInfo;
    NET_ITS_PICTURE_INFO struPicInfo[6];
}NET_ITS_PLATE_RESULT, *LPNET_ITS_PLATE_RESULT;


void CALLBACK MSesGCallback(LONG lCommand, NET_DVR_ALARMER *pAlarmer, char *pAlarmInfo, DWORD dwBufLen, void* pUser)
{
    char filename[100];
    FILE *fSnapPic = NULL;

    switch (lCommand) {

        case COMM_ITS_PLATE_RESULT: {
            NET_ITS_PLATE_RESULT struITSPlateResult = { 0 };
            memcpy(&struITSPlateResult, pAlarmInfo, sizeof(struITSPlateResult));

            printf("Plate: %s\n", struITSPlateResult.struPlateInfo.sLicense);
            if (struITSPlateResult.struPicInfo[0].dwDataLen != 0)
            {
                sprintf(filename, "./pic/%d.jpg", 0);
                fSnapPic = fopen(filename, "wb");
                fwrite(struITSPlateResult.struPicInfo[0].pBuffer, struITSPlateResult.struPicInfo[0].dwDataLen, 1, fSnapPic);
                fclose(fSnapPic);
            }
        }
    }
    return;
}

Delphi代码:

  LPNET_ITS_PICTURE_INFO = ^NET_ITS_PICTURE_INFO;
  NET_ITS_PICTURE_INFO = record
    dwDataLen: DWORD;
    byType: BYTE;
    byAbsTime: array [0..31] of BYTE;
    struPlateRect: NET_VCA_RECT;
    pBuffer: PByte;                  // ????????
    dwUTCTime: DWORD;
    //(...)
  end;


  LPNET_ITS_PLATE_RESULT = ^NET_ITS_PLATE_RESULT;
  NET_ITS_PLATE_RESULT = record
    //(...)
    struPlateInfo: NET_DVR_PLATE_INFO;
    struPicInfo: Array [0..5] of NET_ITS_PICTURE_INFO;
  end;


procedure MessageCallBack(lCommand:longint; pAlarmer:LPNET_DVR_ALARMER; pAlarmInfo:PAnsiChar; dwBufLen:LongInt; pUser:pointer); stdcall;
var
 struAlarmInfo: LPNET_DVR_ALARMINFO_V30;
 struPlateResult: LPNET_ITS_PLATE_RESULT;
begin
  case lCommand of
    COMM_ITS_PLATE_RESULT:
      begin
        New(struPlateResult);
        FillChar(struPlateResult^, SizeOf(NET_ITS_PLATE_RESULT), 0);
        Move(pAlarmInfo^, struPlateResult^, Sizeof(NET_ITS_PLATE_RESULT));
        Form1.memoOut.Lines.Add('sLicense: ' + struPlateResult.struPlateInfo.sLicense);

        if (struPlateResult.struPicInfo[0].dwDataLen >0) then
          ??? how to get the picture from struPlateResult.struPicInfo[0].pBuffer ?

      end;
  end;
end;

致谢

1 个答案:

答案 0 :(得分:1)

是的,PBytePByteArray是正确的翻译。

如果缓冲区包含有效的文件内容,则可以将其保存到文件中

FS := TFileStream.Create('test.jpg', fmCreate);
try
   FS.Write(struITSPlateResult.struPicInfo[0].pBuffer^,
            struITSPlateResult.struPicInfo[0].dwDataLen);
finally
  FS.Free;
end;