0
votes

Im having problems using data from the host application.
I want to send a string through the dll into the host, then combine it with some data from the host app.

By just including the form in the uses clauses i can use methods to send data into the host, When the data is recived i try to add a lokal variable, this is when i get a access violation:

Host:

procedure TMainForm.DllLink(sMessage: String);
begin
    try
      //This is ok:
      Showmessage(sMessage);
      //This is causes Access error:
      Showmessage(sMessage +sPid);
    except
      Showmessage('Access violation');
    end;
end;

Dll:

procedure Transfer(sMessage: PChar); stdcall;
var
sMyPid : String;
begin
    try
       //Get error if i try to use this method to get sPid which is a string:
       sMyPid := MainForm.GetPid; 
       //Or this:
       MainForm.NextsysDllLink(sMessage);
    except
        showmessage('Error');
    end;    
end;

I dont think the dll is using the running applications forms that is what's causing the access violations (maybe im wrong ?) How do I make the dll aware of a running application(that is its host app.) and use that instance to ether get or manipulate data from itself ?

Im using Delphi 5.

2

2 Answers

1
votes

It is recommend to not pass native Delphi Objects between Application and DLL boundaries.
If you want to do that you should be using Packages instead of DLLs.

Global variables are not shared between application and Dll.

n your case, your referencing the global mainform variable in the DLL, if you debug that code you will find that mainform = nil or another address that is not the same as the mainform in your host application.

0
votes