Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling a C++ DLL in Delphi

Status
Not open for further replies.

Gigatech

Programmer
Jul 12, 2000
80
CR
Hi, I use Delphi 7. I have the following declaration of a C++ DLL Function:

UFS_STATUS UFS_API UFS_Extract(
HUFScanner hScanner,
unsigned char* pTemplate,
int* pnTemplateSize,
int* pnEnrollQuality
);

I declared in Delphi as:

function UFS_Extract(hScanner : Longint; var pTemplate :pByteArray; var pnTemplateSize :Longint; var pnEnrollQuality :Longint) :UFS_Status;stdcall external 'UFScanner.dll' name 'UFS_Extract';

It runs fine and I get the values of pnTemplateSize and pnEnrollQuality, but I don´t know how to access the pTemplateArray.

the body of the function that calls this function is:

var
fpBuffer : Array of PByte;
TSize, Quality : Longint;
begin
SetLength(fpBuffer,MAX_TEMPLATESIZE);
ufs_result:=UFS_Extract(Lector,PByteArray(fpBuffer[0]), TSize,Quality);
SetLength(fpBuffer,TSize);

I tried for example b:=fpBuffer[0]^ (where b is byte) but I get an access violation.

Any idea?

The correct code in VB6 is:

Dim hScanner As Long
Dim ufs_res As UFS_STATUS
Dim Template(MAX_TEMPLATE_SIZE - 1) As Byte
Dim TemplateSize As Long
Dim EnrollQuality As Long

ufs_res = UFS_Extract(hScanner, Template(0), TemplateSize, EnrollQuality)


Thanks
 
The Delphi simple Byte data type would correspond to the VB Byte type. (Where'd you get PByte?)

Also, your SetLength statement looks like the second argument should be Pred(MAX_TEMPLATESIZE) to match the VB code. Overrunning array bounds would, I think, give you an access error, which you're seeing.
 
Oh, and probably the most significant piece of this puzzle is that VB parameters are references by default, and Delphi's are value parameters. It looks like you are trying to pass values rather than the addresses of the values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top