Link to home
Start Free TrialLog in
Avatar of loba73
loba73

asked on

Convertion SDK Vc++ to Delphi - fingerprint reader

Hi,

i have a problem with a fingerprint reader. My SDK is in Vc++ and i need to write the application in Delphi.

Could you help me ?

I try with the code found in this site and it work well, but when i verify never pass.
If I build in Vc++ the code it works fine.

This is the procedure in VC++ and bottom the same in Delphi where never verify finger :

********* VC++ *************
void
CHM120SS500ASDK4DemoAPDlg::OnDoenroll() {
    BYTE        pEnrolledFeatures[PTFV_MAX_TEMPLATE_SIZE];
    int         iStatus         = 1;
    DWORD       iEnSize;
    BOOL        bret;
    int         sensor_timeout  = 10000;
    char        pctmp[128];
      int                  iQStatus;
    bsweep = true;
    while ((iStatus > 0) && (bsweep)) {
        memset(m_pPicture, 0x00, SENSOR_HEIGHT * SENSOR_WIDTH);
        m_status.SetWindowText("Sweep your finger...");
        m_iWidth = SENSOR_WIDTH;
        m_iHeight = SENSOR_HEIGHT;
        bret = bAPI4_GetImage(m_pPicture, sensor_timeout, SENSOR_RESOLUTION,
                              &m_iWidth, &m_iHeight, &iQStatus);    

        if (SENSOR_OK != bret) {
            m_status.SetWindowText("Get finger image failed");
            return ;
        } else {
            m_status.SetWindowText("Get Image OK!");
        }

        if (!bAPI4_PTFVEnroll(SENSOR_RESOLUTION, SENSOR_WIDTH, SENSOR_HEIGHT,
                              m_pPicture, pEnrolledFeatures, &iEnSize,
                              &iStatus)) {
            m_status.SetWindowText("Enrolled error!");
            bsweep = 0;
        }

            //m_iEnroll++;
            //sprintf(pctmp, "%d", iEnSize);
            //MessageBox(pctmp);

        this->InvalidateRect(NULL, TRUE);    
        this->UpdateWindow();
    }  

    switch (iStatus) {
      case PTFV_STS_EN_SUCCESS:
        memcpy(m_SAbuf + m_iEnroll * PTFV_MAX_TEMPLATE_SIZE,
               pEnrolledFeatures, PTFV_MAX_TEMPLATE_SIZE);
        m_iEnroll++;
        sprintf(pctmp, "*** The %d-th finger enrolled ***", m_iEnroll);
        if (MAX_ENROLLED_FINGER_NUM == m_iEnroll) {
            m_iEnroll--;
        }              
        m_status.SetWindowText(pctmp);
        break;
      case PTFV_STS_EN_TOOMANY_POORIMG:
        m_status.SetWindowText("'MAX_POOR_IMAGE_TOLERANCE' of poor image met");
        break;
      case PTFV_STS_EN_TOOMAY_TRIALS:
        m_status.SetWindowText("Too many useless sweepings (12 times in default)");
        break;
      case PTFV_STS_EN_FAIL:
        m_status.SetWindowText("Enrolled failed");
        break;
      case PTFV_STS_EN_CONTINUE:
        m_status.SetWindowText("Button 'Stop Getting Image' pressed");
        break;
    }
     
    GetDlgItem(IDC_DOENROLL)->EnableWindow(FALSE);
}

****** DELPHI *******
In delphi the part of code that seem wrong is :


procedure TForm1.EnrollClick(Sender: TObject);
Var
  iWidth, iHeight, TimeOut, iEnSize, iStatus,iStatusImg, Num: Integer;
  r_value, r_value2: Boolean;
  bsweep: Boolean;
  EnrlTemplate: TMyByteArray      ;
  m_Picture: TMyByteArray;
  bmpFinger:TBitmap;
   i:Integer;
begin
  SetLength(EnrlTemplate,(PTFV_MAX_TEMPLATE_SIZE) );
    SetLength(m_Picture,(SENSOR_WIDTH * SENSOR_HEIGHT) );

  TimeOut := 10000;
  bsweep := True;
  iStatus := 1;
  m_iEnroll := 0;

  While (iStatus > 0) And (bsweep = True) Do
  Begin
    m_Picture:=nil;
    SetLength(m_Picture,(SENSOR_WIDTH * SENSOR_HEIGHT) );

    iWidth := SENSOR_WIDTH ;
    iHeight := SENSOR_HEIGHT;

    Label1.Caption := 'Put your finger on sensor + ...'+ IntToStr      (m_iEnroll);
    Application.ProcessMessages;

    r_value := bAPI4_GetImage(@m_Picture[0], TimeOut, SENSOR_RESOLUTION, iWidth, iHeight,iStatusImg);

    if r_value = False Then
    Label1.Caption := 'Get finger image failed!'
    Else
    Label1.Caption := 'Get Image OK!';

    r_value2 := bAPI4_PTFVEnroll(SENSOR_RESOLUTION, iWidth, iHeight,
                                    @m_Picture[0], @EnrlTemplate[0], iEnSize, iStatus);

     bmpFinger:= TBitmap.Create;
    bmpFinger.Width:=    iWidth;
    bmpFinger.Height:=    iHeight;
    bmpFinger.PixelFormat:= pf8bit;

    BytesToBitmap(m_Picture, bmpFinger,
    pf8bit,
    bmpFinger.Width,
    bmpFinger.Height);
    Image1.Picture.Bitmap.Assign(bmpFinger);


    if r_value2 = False Then
    Begin
      Label1.Caption := 'Enrolled error!';
      bsweep := False;
    End;

  End;

  Case iStatus Of
  PTFV_STS_EN_SUCCESS:
               Begin
               // ********** THIS PART IS DIFFERENT FROM VC++ using MemCpy ************
               Label1.Caption := 'Enrolled OK!';
               For Num := 0 To PTFV_MAX_TEMPLATE_SIZE -1 Do
                    m_SAbuf[m_iEnroll * PTFV_MAX_TEMPLATE_SIZE + Num] := EnrlTemplate[Num];
               End;

   PTFV_STS_VF_FAIL:  Begin
                      Label1.Caption := ' PTFV_STS_VF_FAIL !';
   End;
     PTFV_STS_EN_TOOMANY_POORIMG:  Begin
                      Label1.Caption := ' PTFV_STS_EN_TOOMANY_POORIMG!';
   End;
      PTFV_STS_EN_TOOMAY_TRIALS:  Begin
                      Label1.Caption := ' PTFV_STS_EN_TOOMAY_TRIALS!';
   End;
  End;
end;

and in the verify

procedure TForm1.VerifyPBClick;
var
...
...
begin
...

r_value2 := bAPI4_PTFVVerify(SENSOR_RESOLUTION, iWidth, iHeight,
                                @m_Picture[0], @m_SAbuf[0], m_iEnroll, iMatchID, iStatus);

   
  if r_value2 Then
    if (iStatus = PTFV_STS_VF_SUCCESS) Then  
       begin
       // ************************************
       // ***** IN DELPHI NEVER ENTER HERE *****
       //************************************
       label1.Caption := '*** Verify Pass! ' + IntToStr(iMatchID)
       end  
    Else
    label1.Caption := 'No Pass';
end;


Thanks in advance.
Avatar of developmentguru
developmentguru
Flag of United States of America image

The only thing that jumps out at me is that the boolean should most likely be word bool.  I will need to look at it more when I have time.
WordBool
ASKER CERTIFIED SOLUTION
Avatar of loba73
loba73

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dirk Haest
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.