Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

Help to create a Dll and pass a string to it.

Hello guys,

I create a simple dll and application that I only call a method and it display "Ā hello world ".

Now I need to create a function where I can pass a string to it and do it display my message, take a look at my code:

Dll created

library DllCrystal;

uses
  SysUtils,
  Classes,
  Dialogs;

{$R *.res}

procedure DllMessage; export;
begin
  ShowMessage('Hello world from a Delphi DLL') ;
end;
 
 exports DllMessage;

begin
end.

Open in new window


My application that calls the DLL

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  procedure DllMessage; external 'DllCrystal.dll';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  DllMessage
end;

end.

Open in new window



Now, I need a simple help from you how to do that, create a correct function and call the function in application passing the value to it.

thanks a lot
alex
ASKER CERTIFIED SOLUTION
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hidrau

ASKER

Thanks a lot for your help. I was afraid to do something wrongly
Avatar of hidrau

ASKER

Ferruccio Accalai

Can I pass long string to a dll?
Can I have in my function a constant value? I am trying but I am getting error
Avatar of hidrau

ASKER

thanks a lot