Jump to content
PeterPanettone

How to use library from Delphi 10.1 DCUs in Delphi 10.3.3?

Recommended Posts

Unfortunately, I have a specific library for which I have only Delphi 10.1 Berlin DCUs (no source code), but I need to use this library in Delphi 10.3.3 Rio.

 

Which is the best strategy to achieve this? (DLLs, Packages, ...)

Edited by PeterPanettone

Share this post


Link to post

Build the dcus into a dll and link to that.

 

You can't use packages because you can only link packages that were compiled with the same compiler. 

 

That's a short term solution. Long term you should replace the library. 

  • Like 2

Share this post


Link to post
16 hours ago, David Heffernan said:

That's a short term solution. Long term you should replace the library.

That is OBVIOUS.

Share this post


Link to post
17 hours ago, David Heffernan said:

Build the dcus into a dll and link to that.

Can you indicate me a practical example?

 

(There is no theory about the difference between theory and practice)

Edited by PeterPanettone

Share this post


Link to post

Done. It works, but when I close the host exe it CRASHES. The exe also crashes on Close even if I don't press the button!

 

See attachment:

 

TestDLL.zip

Edited by PeterPanettone

Share this post


Link to post
16 minutes ago, PeterPanettone said:

when I close the host exe it CRASHES. The exe also crashes on Close even if I don't press the button!

After having removed ShareMem from the uses list in both the DLL and the host exe, it does not crash anymore!

Share this post


Link to post

You don't need LoadLibrary/FreeLibrary if you use a static function definition like "external myDLL". So use either LoadLibrary/GetProcAddress/FreeLibrary or use function/external myDLL.

 

Also... you use a string as parameter. That is a managed type. I'm not sure but that might give you problems.

 

  • Thanks 1

Share this post


Link to post
28 minutes ago, rvk said:

You don't need LoadLibrary/FreeLibrary if you use a static function definition like "external myDLL". So use either LoadLibrary/GetProcAddress/FreeLibrary or use function/external myDLL.

 

Also... you use a string as parameter. That is a managed type. I'm not sure but that might give you problems.

 

I have changed the code using PWideChar now:

 

DLL:

 

function JclShell_DisplayPropDialog(AHandle: THandle; AFile: PWideChar): Boolean; stdcall;
begin
  Result := JclShell.DisplayPropDialog(AHandle, string(AFile));
end;

 

Host exe:

 

function JclShell_DisplayPropDialog(AHandle: THandle; AFile: PWideChar): Boolean; stdcall; external myDLL;

procedure TForm3.btnTestClick(Sender: TObject);
begin
  if JclShell_DisplayPropDialog(0, PWideChar(edtFile.Text)) then
    Self.Caption := 'Success'
  else
    Self.Caption := 'Failure';
end;

 

It does work well, no crash. :classic_smile:

Share this post


Link to post
On 1/27/2020 at 7:30 PM, David Heffernan said:

Build the dcus into a dll and link to that.

This is a ridiculously perfect and simple idea. Fortunately I have source for everything, but I'll keep this in my mind for later!

Share this post


Link to post

It is a good way of black-boxing old code.

The drawback of using DLLs is that versioning the interface becomes important.

 

Want to add a parameter to a function? 

It will break the compatibility with the old DLL, so better to add a second function.

 

Want to change a structure?

Another break - unless you planned for it and have structure versioning and size info, and always add content at the end of the structure.

 

Win32 is jam-packed with the above.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×