SDK 指针问题 - c++ 到 Delphi 翻译

Problem with SDK pointers - c++ to Delphi translating

我正在努力使用 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;

此致

是的,PBytePByteArray 是正确的翻译。

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

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