PeterPanettone 158 Posted January 27, 2020 (edited) 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 January 27, 2020 by PeterPanettone Share this post Link to post
David Heffernan 2353 Posted January 27, 2020 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. 2 Share this post Link to post
PeterPanettone 158 Posted January 28, 2020 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
PeterPanettone 158 Posted January 28, 2020 (edited) 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 January 28, 2020 by PeterPanettone Share this post Link to post
David Heffernan 2353 Posted January 28, 2020 Start by following a tutorial on how to create a dll and export a simple function. Work up from there. Share this post Link to post
PeterPanettone 158 Posted January 28, 2020 (edited) 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 January 28, 2020 by PeterPanettone Share this post Link to post
PeterPanettone 158 Posted January 28, 2020 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
rvk 44 Posted January 28, 2020 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. 1 Share this post Link to post
PeterPanettone 158 Posted January 28, 2020 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. Share this post Link to post
aehimself 399 Posted January 29, 2020 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
Lars Fosdal 1793 Posted January 30, 2020 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. 1 Share this post Link to post