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'
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'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I don't wan't to call a delphi function that then calls a
Dll !!
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
>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
ASKER
I don't wan't to call a delphi function that then calls a
Dll !!
Dll !!
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 !!
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
Ciao, Mike
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 !!
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 !!
ASKER
ok better late than never !!
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;