Now I'm trying to get the picture from my Dahua Terminal, and the code becomes a little trick.
In C++ sample code, I have:
//Struct
// face info
typedef struct tagNET_ACCESS_FACE_INFO
{
char szUserID[32]; // user ID
int nFaceData; // count of face data,the max number is 20
char szFaceData[20][2048]; // face data
int nFaceDataLen[20]; // face data length
int nFacePhoto; // count of face photo,max size: 5
int nInFacePhotoLen[5]; // the size of each photo used by the user
int nOutFacePhotoLen[5]; // the actual size of each photo
char* pFacePhoto[5]; // face photo data,max size: 120K
BYTE byReserved[2048]; // reserved
} NET_ACCESS_FACE_INFO;
//Part of the c++ code
//...
NET_ACCESS_FACE_INFO stuFaceInfo;
memset(&stuFaceInfo,0,sizeof(stuFaceInfo));
for (int i=0;i<5;i++)
{
stuFaceInfo.nInFacePhotoLen[i] = 100*1024;
stuFaceInfo.pFacePhoto[i] = new char[100*1024]; //<-- Don´t know how do it
memset(stuFaceInfo.pFacePhoto[i],0,100*1024);
}
stuFaceGetOut.pFaceInfo = &stuFaceInfo;
I convert to this Delphi code:
// face info Record
PNetAccessFaceInfo = ^TNetAccessFaceInfo;
TNetAccessFaceInfo = record
szUserID: array[0..31] of AnsiChar; // user ID
nFaceData: Integer; // count of face data,the max number is 20
szFaceData: array[0..19, 0..2047] of AnsiChar; // face data
nFaceDataLen: array[0..19] of Integer; // face data length
nFacePhoto: Integer; // count of face photo,max size: 5
nInFacePhotoLen: array[0..4] of Integer; // the size of each photo used by the user
nOutFacePhotoLen: array[0..4] of Integer; // the actual size of each photo
pFacePhoto: array[0..4] of PAnsiChar; // face photo data,max size: 120K
byReserved: array[0..2047] of Byte; // reserved
end;
...
var
faceInfo: TNetAccessFaceInfo;
begin
...
ZeroMemory(@faceInfo,sizeOf(faceInfo));
for I := 0 to 4 do
begin
faceInfo.nInFacePhotoLen[i] := 100*1024;
ZeroMemory(@faceInfo.pFacePhoto[i],sizeof(faceInfo.pFacePhoto[i])); //<-- this get nothing, no error code, no crash
// faceInfo.pFacePhoto[i] := pAnsichar(100*1024); //<-- tryed this but got a exception
FillChar(faceInfo.pFacePhoto[i],0,100*1024);
end;
With pFacePhoto *char[5] I convert to pFacePhoto : Array [0..4] of PAnsiChar;
But in the sample code, ...pfacePhoto[i] = new char[100*1024] in my limited knowledge of C++ means the PAnsiChar receiving a Delphi array [0..(100*1024)-1] of AnsiChar.
Since pFacePhoto[i] is a PAnsiChar, can I create a new array of AnsiChar and point to it?
Running my Delphi code, I get this from GetLastError():
#define NET_RETURN_DATA_ERROR _EC(21) // Error occurs when verify returned data.