: : : Hi,
: : : I am using Delphi5. I have made a DLL. In DLL there is a unit (with form i.e. GUI) named uExport. As you know that any form in the Delphi is itself a class. I have written a public function in this Form class.
: : : Now I want to import the same. To do so I had written Export and stdcall at the end of function declaration and definition.
: : : The DLL is getting built properly. I also have a stand alone EXE to test DLL.
: : : When I use the exported function of DLL in said exe, it (exe) does not give any problem or error but at the same time it doesnot produce any result.
: : : To know the reason I debugged the DLL code but the control does not ever enter in the exported function of form class.
: : :
: : : At the same time the control does enter in the exported function if it is global and not in the class.
: : :
: : : Please tell me how to export a function of any class from Delphi DLL?
: : :
: : : Bye.
: : : Chaitanya.
: : :
: : Perhaps you forgot the exports clause in the DLL. For any Win32 DLL, the export directive is ignored, only the exports clause in the DLL determines if a routine is exported.
: : Also you cannot export methods directly, because they consist of 2 pointers: the procedure pointer and the object pointer.
: :
: ------------------------------------------------------------------------
:
: Hi thanks for reply.
: I have not forgotten to add Export clause in DLL.
: Then what should be the reason? Please explain in detail.
:
:
Without seeing the relevant parts of the code, there can be several reasons:
- exported name and imported name are different.
- parameter lists are not compatible (ie number, order and types are different)
- routine call is different (ie pascal vs c vs StdCall vs SafeCall)
- routine is not listed in exports clause (which is different from the export directive).
- routine is a method instead of a procedure or a function (methods consist of 2 pointers)
Example of working DLL export:
library ExampleDLL;
uses
Dialogs;
procedure ShowText(Text: PChar); StdCall;
begin
ShowMessage(Text);
end;
exports
ShowText;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
procedure ShowText(Text: PChar); StdCall; external 'ExampleDLL.dll';
implementation
{$R *.DFM}
procedure TForm2.Button1Click(Sender: TObject);
begin
ShowText('Hello World');
end;
end.