Ver Mensaje Individual
  #1  
Antiguo 08-02-2014
mordaz mordaz is offline
Miembro
 
Registrado: mar 2008
Posts: 32
Reputación: 0
mordaz Va por buen camino
Smile Digital Persona SDK en C++ Builder

Buenos dias,

Estoy tratando de traducir el código de ejemplo del SDK del lector biometrico Digital Persona de un ejemplo de Delphi a C++ Builder, pero no logro hacerlo funcionar correctamente.

El código original es el siguiente:

Código Delphi [-]

procedure TForm1.SaveTemplate();
 var
outFile : File of byte;
vrnt: Variant;
vtByteBuf : PByteArray;
aryLow: integer;
aryHigh : integer;
rawDataSize: integer;
loopIndex : integer;
numWritten : integer;
bt : byte;
iTemplate : DPFPShrXLib_TLB.IDPFPTemplateDisp;
begin

try
if SaveDialog.Execute then
      begin
iTemplate := DPFPEnrollment.Template as DPFPShrXLib_TLB.IDPFPTemplateDisp;
vrnt:=iTemplate.Serialize;  //raw data is now stored in this variant

        //Now that you have the variant, try to get raw byte array
        //We are assuming here that you cannot save a variant directly to database field
        //That you need a byte array before saving the data to the database.
        
        aryLow:=VarArrayLowBound(vrnt,1);
        aryHigh:=varArrayHighBound(vrnt,1);
        aryHigh:=aryHigh-aryLow;

        vtByteBuf:=VarArrayLock(vrnt);  //lock down the array
        AssignFile(outFile,saveDialog.FileName);
        Rewrite(outFile);
        for loopIndex := 0 to aryHigh  do
        begin
               //fpData[loopIndex]:=vtByteBuf[loopIndex];
               //bt:=fpData[loopIndex];
               Write(outFile,vtByteBuf[loopIndex]);  //Save directly to file here
        end;
        VarArrayUnlock(vrnt);
      end;
except
on E: Exception do showmessage('Trouble saving data');
end;
        CloseFile(outFile);


end;

Mi codigo en C++ Builder es el siguiente

Código:
void __fastcall TForm1::btnSaveClick(TObject *Sender)
{
  //Guardando la muestra
  OleVariant Ovt;
  IDispatch &pSample=static_cast<IDispatch&>(*DPFPEnrollment->Template);
  IDPFPSample &Muestra=static_cast<IDPFPSample&>(pSample);
  Muestra.Serialize(Ovt);

  //Guardando en archivo
  int aryLow;
  int aryHigh;
  Variant vrnt;
  vrnt=reinterpret_cast <Variant&> (Ovt);
  aryLow=VarArrayLowBound(vrnt,1);
  aryHigh=VarArrayHighBound(vrnt,1);
  aryHigh=aryHigh-aryLow;
  PByteArray vtByteBuf=(PByteArray)VarArrayLock(vrnt);

  ofstream myfile;
  myfile.open ("muestra.bin", ios::out | ios::app | ios::binary);
  for (int loopIndex=0;loopIndex<=aryHigh;loopIndex++){
     myfile<<vtByteBuf[loopIndex];
  }
  VarArrayUnlock(vrnt);
  myfile.close();
}
El código me genera correctamente el archivo "muestra.bin" pero al compararlo en tamaño con uno generado con Delphi existe una diferencia en tamaño considerable. Lo que me hace suponer que no estoy guardando los datos correctamente.

Gracias por su apoyo.

Última edición por Casimiro Notevi fecha: 08-02-2014 a las 10:38:10.
Responder Con Cita