Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi C++ DLL Header -> Delphi (Struct) (https://www.delphipraxis.net/98595-c-dll-header-delphi-struct.html)

f.siebler 29. Aug 2007 14:40


C++ DLL Header -> Delphi (Struct)
 
Moin Moin,

so langsam blicke ich bei der übersetzung durch, naja zumindest bei den einfachen dingen :-)

Nun ist bei mir leider ein neues Problem aufgetreten, und zwar das folgende:

Code:
//$e-----------------------------------------------------------------------------------------------
//   @EnrollEx
//
//   Function   :   Enrolls one finger : Creates a template from a set of acquisitions.
//
//   Input      :   pstEnrolledTemplate->dwTemplateSize supplies the buffer size.
//                  (must be at least TEMPLATE_SIZE).
//                  pUpdateFunc points to a callback function that updates execution status.
//                  pvObject points to an object (context) used by pUpdateFunc.               
//               pCompletionRoutine points to a completion routine called when the operation
//               ends. If this callback is defined, this function behaviour
//                  is asynchronous (See Info section)
//               pvContext points to a context passed to pCompletionRoutine.
//
//   Output      :   pstEnrolledTemplate points to the enrolled template if the operation
//                  succeeded.
//
//  Returns      :   RCDone if the operation succeeded.
//               RCFailed if the operation failed.
//               RCAborted if the operation has been aborted.
//               RCNoDevice if no acquisition device has been found.
//               RCNoSensor if there is no sensor or if the sensor is defective.
//               RCOpenFailed if there is a problem while opening the device.
//               RCBufferTooSmall if the buffer named pstEnrolledTemplate->pbyTemplate is too small
//               RCAllocationFailed if a dynamic allocation failed
//               (lack of memory resource)
//
//   Info      :   If pCompletionRoutine is NULL, this function will not return until the end
//                  of the operation, and will consequently have a synchronous behaviour.
//$e-----------------------------------------------------------------------------------------------
DLLIMPORT DWORD EnrollEx( PSTBioTemplateEx const pstEnrolledTemplate,
                      void (*pUpdateFunc)(PVOID,DWORD) = NULL,
                      PVOID pvObject = NULL,
                      void (*pCompletionRoutine)(DWORD,PVOID) = NULL,
                      PVOID pvContext = NULL);

//$e-----------------------------------------------------------------------------
Code:
// Template
typedef struct {
   DWORD dwTemplateSize;
   DWORD dwTemplateID;
   BYTE* pbyTemplate;
} STBioTemplateEx, *PSTBioTemplateEx;
Daraus habe ich bisher folgendes gemacht:

Delphi-Quellcode:
type
  PSTBioTemplateEx = packed record
     dwTemplateSize : DWORD;
    dwTemplateID : DWORD;
    pbyTemplate: array [0..288] of DWORD;
  end;

function EnrollEx (pstEnrolledTemplate : Pointer; pUpdateFunc : Pointer; pvUpdateCOntext : Pointer; pCompletionRoutine: Pointer; pvCompletionContext : Pointer): DWORD; cdecl; external 'BiometricDll.dll';
probleme bereitet mir der erste Parameter, ich habe ich schon die folgende Funktion Variante getestet:

Delphi-Quellcode:
function EnrollEx (var pstEnrolledTemplate : PSTBioTemplateEx ; pUpdateFunc : Pointer; pvUpdateCOntext : Pointer; pCompletionRoutine: Pointer; pvCompletionContext : Pointer): DWORD; cdecl; external 'BiometricDll.dll';
Leider bisher alles ohne Erfolg, ich vermute, dass ich mich irgendwo grundlegend verrant habe :-)
Ich bekomme keine Fehlermeldung zurück, aber das Gerät macht nichts, in anderen Anwendungen geht es wunderbar :-( (Demo Project in C++)

Wer von euch hat ne Idee! Wäre super...! Und mit "Erklärung" wäre es genial..

Besten Dank &

f.siebler 29. Aug 2007 15:08

Re: C++ DLL Header -> Delphi (Struct)
 
Ist erst mal erledigt, die Größe von

Delphi-Quellcode:
 pbyTemplate: array [0..648] of DWORD;
war falsch....

Danke :-)

Robert Marquardt 29. Aug 2007 15:48

Re: C++ DLL Header -> Delphi (Struct)
 
Delphi-Quellcode:
type
  TUpdateFunc = procedure(Param1: Pointer; Param2: DWORD); cdecl;
  TCompletionRoutine = procedure(Param1: DWORD; Param2: Pointer); cdecl;

function EnrollEx(var stEnrolledTemplate: STBioTemplateEx; UpdateFunc: TUpdateFunc = nil; pvUpdateCOntext: Pointer = nil;
  CompletionRoutine: TCompletionRoutine = nil; pvCompletionContext: Pointer = nil): DWORD; cdecl; external 'BiometricDll.dll';
Der erste Parameter stEnrolledTemplate war falsch deklariert. Das var bewirkt eine Indirektion, also ist der Typ vom Pointer auf die Struktur aud den Strukturtyp zu aendern.
Die Parameter sind Callback-Prozeduren und ein zugehoeriger Context-Pointer den man bestimmt zu beliebigen Zwecken einsetzen kann. Der duerfte als der Pointer-Parameter der Callback-Prozedur uebergeben werden.
Die Defaultwerte fuer die Parameter kann man auch in Delphi implementieren.

f.siebler 31. Aug 2007 15:00

Re: C++ DLL Header -> Delphi (Struct)
 
Danke! Läuft alles :-)


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:25 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz