2
votes

I have a DLL that has a Form. I have an application that calls this DLL. I'm trying to put a Caption in the Form inside the DLL through the Application's call.

Here is how the DLL creates the Form:

procedure CallEmployee(Title: PWideChar); export; stdcall;
begin
   Frm_Standard := TFrm_Standard.Create(nil,DA,[],[]); //I have a modified Constructor
   Frm_Standard.Caption := Title;

This is the declaration of the DLL's procedure in the Application:

procedure CallEmployee(Title: PWideChar); external 'Employee.dll';

And this is how I'm making the call right now:

//I wanna put a title according to an specific test (Not this one, obviously)
if 2 = 2 then 
  CallEmployee(PWideChar('This Title'));

I'm using PWideChar because I found out that String doesn't work in this situation.

It must be something small that I'm missing, but I researched and I just couldn't find a solution.

I find a few things for Functions, but since I don't need to return any parameters, I'm using a simple procedure. Or that might be the root of my problems, to begin with?

I'm using Delphi XE7.

And sorry if this question is irrelevant or has already been asked, but I couldn't find it. If it already has an answer, just tell me and I'll delete this question.

Ah, everything else works perfectly, the procedure calls the Form, it is shown correctly, but the title always comes out like this:

Weird Title

1
An aside, the export directive is ignored, you should remove it so that you don't think it actually means anything!David Heffernan
you forgot stdcall; on the caller declarationArioch 'The
Also consider using BPL instead of DLL - that way you would be both able to pass strings as is and be safe from such simple to make hard to find an error, because the compiler would check the correctness fo all the datatypes including function declarationArioch 'The
BPLs are usually pointless at runtime. You'd usually compile the code into one module, if you controlled it all. Multiple modules are useful when you want to support mutiple hosts. At which point BPLs are no use.David Heffernan

1 Answers

2
votes

You missed the calling convention. Replace:

procedure CallEmployee(Title: PWideChar); external 'Employee.dll';

with

procedure CallEmployee(Title: PWideChar); stdcall; external 'Employee.dll';