Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Problem in Exporting a function from DLL Posted by Chaitanya_Pune on 3 Aug 2006 at 3:43 AM
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.
Report
Re: Problem in Exporting a function from DLL Posted by zibadian on 3 Aug 2006 at 4:16 AM
: 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.
Report
Re: Problem in Exporting a function from DLL Posted by Chaitanya_Pune on 5 Aug 2006 at 3:39 AM
: : 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.

Report
Re: Problem in Exporting a function from DLL Posted by zibadian on 5 Aug 2006 at 4:09 AM
: : : 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.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.