Delphi – How to call a Delphi DLL from VB6

declaredelphidllvb6

Given the following Delphil DLL declaration

function csd_HandleData(aBuf: PChar; aLen: integer): integer; stdcall;

what would be the VB6 declaration to use it?

I've tried a variety of declarations, e.g.

Declare Function csd_HandleData Lib "chsdet.dll" (ByVal aBuf As String, ByVal aLen As Integer)
Declare Function csd_HandleData Lib "chsdet.dll" (aBuf As Long, ByVal aLen As Integer)
Declare Function csd_HandleData Lib "chsdet.dll" (aBuf As Byte, ByVal aLen As Integer)

with the relevant code to suit the parameters, but nothing seems to work, i.e. the Delphi debugger says I have a too-largish value in aLen and a null string in aBuf.

I am working toward using a TypeLib to drive the connection, but was prototyping with Declares.

Best Answer

try

Declare Function csd_HandleData Lib "chsdet.dll" (ByVal aBuf As String, 
ByVal aLen As Integer) As Integer

Seems you forgot the return value.