Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem in Exporting a function from DLL

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.

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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.
  • Chaitanya_PuneChaitanya_Pune Posts: 87Member
    : : 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.

  • zibadianzibadian Posts: 6,349Member
    : : : 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:
    [code]
    library ExampleDLL;

    uses
    Dialogs;

    procedure ShowText(Text: PChar); StdCall;
    begin
    ShowMessage(Text);
    end;

    exports
    ShowText;
    end.
    [/code]
    [code]
    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.
    [/code]
Sign In or Register to comment.