Recent

Author Topic: Problems to translate header C of Digital Persona to Pascal  (Read 4663 times)

tadryanom

  • New Member
  • *
  • Posts: 15
Problems to translate header C of Digital Persona to Pascal
« on: November 03, 2018, 02:21:28 am »
Hello guys. I'm in one of my programming adventures where I'm trying to translate the biometric library from Digital Persona Inc. (dpfpdd.h) to Pascal.

I used the http://wiki.freepascal.org/Creating_bindings_for_C_libraries tutorial as a basis to do the translation. Since I have the .pas file completed, I compile it without errors. However, trying to make works it seem that some things are wrong about types, structures, and pointers.

I wonder if they can help me with some kind of solution.

Below is the link to the sources.

Translated .pas file: https://pastebin.com/T982jNhk

Original .h file: https://pastebin.com/vyCWDrq1

Sample .pas file: https://pastebin.com/aHb9UZkB

Sample C: https://pastebin.com/wxbPPm5y

Link to SDK for Windows: http://crm.computerid.com.br/Suporte/DigitalPersona/SDK/U.are.U/UareUWin300_20170223.1115.zip

Link to SDK for Linux: http://crm.computerid.com.br/Suporte/DigitalPersona/SDK/U.are.U/CM-UareU-SDK-3.0.0-1.20170520_1651.zip

NOTE 1: The C code works for all functions. In the case of pascal code, only the dpfpdd_init () function works, the dpfpdd_version () and dpfpdd_query_devices () functions have errors in their output, the .h or .pas header has definitions of the meaning of those errors.

NOTE 2: For the tests I used a biometric reader Digital Persona UareU 4000B

Sorry for my lousy English.

Grateful for the attention.

« Last Edit: November 03, 2018, 09:21:57 pm by tadryanom »

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Problems to translate header C of Digital Persona to Pascal
« Reply #1 on: November 03, 2018, 06:31:58 am »
add {$packrecords C}  (and don't use pastebin, but zip and attach the source)
Specialize a type, not a var.

tadryanom

  • New Member
  • *
  • Posts: 15
Re: Problems to translate header C of Digital Persona to Pascal
« Reply #2 on: November 03, 2018, 02:12:22 pm »
Sorry for not adding the compressed files. I added {$packrecords C} as you suggested, but it still results in the same errors: 96075796 when executing dpfpdd_version () -> (return: One or more parameters passed to the API call are invalid) and 96075789 when executing dpfpdd_query_devices() -> (return: The memory allocated by the application is not big enough for the data which is expected).

Could I have suggested another alternative?

NOTE: I used the test environment in addition to the ones mentioned above, the following configuration: FPC 3.0.4 running on Ubuntu 18.04 LTS amd64, Intel Core I5 2.5Ghz, 6GB RAM and also tested on Windows 7 32bit running on VirtualBox with 1GB RAM.

« Last Edit: November 03, 2018, 02:17:47 pm by tadryanom »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Problems to translate header C of Digital Persona to Pascal
« Reply #3 on: November 03, 2018, 02:57:57 pm »
also tested on Windows 7 32bit running on VirtualBox with 1GB RAM.

This part looks wrong to me for Win32:
Code: Pascal  [Select][+][-]
  1. {$ifndef DPAPICALL}
  2. {$ifdef Win32}
  3. {$ifdef WinCE}
  4. {$define DPAPICALL := cdecl}
  5. {$else}
  6. {$define DPAPICALL := stdcall}
  7. {$endif}
  8. {$else}
  9. {$define DPAPICALL := cdecl}
  10. {$endif}
  11. {$endif}

Comment it out and test with:
Code: Pascal  [Select][+][-]
  1. {$define DPAPICALL := cdecl}

tadryanom

  • New Member
  • *
  • Posts: 15
Re: Problems to translate header C of Digital Persona to Pascal
« Reply #4 on: November 03, 2018, 03:31:32 pm »
Does not work!

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Problems to translate header C of Digital Persona to Pascal
« Reply #5 on: November 03, 2018, 04:19:48 pm »
Code: [Select]
[quote]The memory allocated by the application is not big enough for the data which is expected) means the API expected a pointer to initialized memory of a given size.
YOU have to allocate that memory and not simply pass a pointer no nothing.
Specialize a type, not a var.

tadryanom

  • New Member
  • *
  • Posts: 15
Re: Problems to translate header C of Digital Persona to Pascal
« Reply #6 on: November 03, 2018, 04:37:00 pm »
I'm not used to Pascal, could you give me an example of how to do it?

tadryanom

  • New Member
  • *
  • Posts: 15
Re: Problems to translate header C of Digital Persona to Pascal
« Reply #7 on: November 03, 2018, 05:35:29 pm »
Quote
YOU have to allocate that memory and not simply pass a pointer no nothing.

I created a project from a console application using Lazarus 1.8.4 compiled with FPC 3.0.4 and I do not know why the hell it worked, just wanted to understand what I'm doing wrong. It follows the application project into a compressed file.

tadryanom

  • New Member
  • *
  • Posts: 15
Re: Problems to translate header C of Digital Persona to Pascal
« Reply #8 on: November 03, 2018, 08:57:11 pm »
I researched some more and found the solution to use the getmem() and freemem() functions for memory allocation. With that, I can make the program finally work.

Please find attached my sample code.

NOTE 1: I will finish converting the remainder of Digital Persona's biometrics library and share my work for community appreciation. As soon as I finish the whole process I will make another post as a link to my work.

NOTE 2: When compiling the same code in Windows I had like return the following error:
--------------------------------------------------------
An unhandled exception occurred at $0025F1D4:
EAccessViolation: Access violation
  $0025F1D4
--------------------------------------------------------

Thank you all for the attention.
« Last Edit: November 03, 2018, 09:21:39 pm by tadryanom »

tadryanom

  • New Member
  • *
  • Posts: 15
Re: Problems to translate header C of Digital Persona to Pascal
« Reply #9 on: November 13, 2018, 03:27:03 pm »
I have finished translating and making my work available in public environment. Follow the link: https://github.com/tadryanom/DigitalPersona_UareU_SDK_to_FreePascal

 

TinyPortal © 2005-2018