Link to home
Start Free TrialLog in
Avatar of Jeb
Jeb

asked on

Calling functions in external DLL's

I have a Delphi class that has to call some functions
in an external DLL !! . . .
It works fine when it's not in a class !!

But it can't compile when it's in a class

const
  DLLNAME = 'DEng32.dll';

type
TDesEng = class(TComponent)
public
 function APICreateSession() : longint; cdecl; external DLLNAME;

I get this errormessage
'Field definitions not allowed after mothods or properties'
Avatar of simonet
simonet
Flag of Brazil image

Take a look at CommCtrl.pas. In that files there are tons of examples on how to import class procedures from DLLs.

The basic approach is to declare the class as if it where a regular class and, only in the implementation section you specify the proc is in a DLL.

there are examples in controls.pas too.

Yours,

Alex

end;

ASKER CERTIFIED SOLUTION
Avatar of Lischke
Lischke

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 Jeb
Jeb

ASKER

I don't wan't to call a delphi function that then calls a
Dll !!  

>I don't wan't to call a delphi function that then calls a
>Dll !!  

But that's the way to do it. Lischke is right.

When you make call a class procedure/function, there is one hidden parameter. You cannot pass this parameter to the DLL, simply because you cannot define it.

Alex
Avatar of Jeb

ASKER

I don't wan't to call a delphi function that then calls a
Dll !!  

Avatar of Jeb

ASKER

ok . . . if it not that much overhead then it's ok !!

I just had it alle in a Unit with the external declaratin, but if it doesn't work for classes then I'll do it the
hard way !!
Jeb, there isn't really much overhead. Actually by calling the class' method it will read pointer and call this then according to the definitions. This happens all the time in much of the Window controls wrapper classe. Believe me, the overhead is marginal compared to all the other things happening in an application.

Ciao, Mike
Avatar of Jeb

ASKER

ok . . . if it not that much overhead then it's ok !!

I just had it alle in a Unit with the external declaratin, but if it doesn't work for classes then I'll do it the
hard way !!
Avatar of Jeb

ASKER

ok  better late than never !!