2800:Calling a Delphi DLL from C
KEYWORDS: Delphi, DLL, C, C++ AREA: General
Calling a DLL from your C Code.
First create a simple DLL in Delphi:
{ Begin DLL code }
Library MinMax;
Function Min(X, Y: Integer): Integer; export;
begin
if X < Y then Min := X else Min := Y;
end;
Function Max(X, Y: Integer): Integer; export;
begin
if X > Y then Max := X else Max := Y;
end;
Exports
Min index 1,
Max index 2;
begin
end.
{ End DLL code }
Then to Call it from your C Code:
1. In your .DEF File add:
IMPORTS
Min =MINMAX.Min
Max =MINMAX.Max
2. In your C application, you must prototype the functions as:
int FAR PASCAL Min(int x, y);
int FAR PASCAL Min(int x, y);
3. Now you can call Min or Max anywhere in your application.
TI