Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem starting program with a dll embedded as a resource

I've done About.com guide to embedding dll's in Delphi EXE's which seems to work, so long as I don't actually use the DLL as an external function. Is there anyway to get the code I linked to to work earlier than an unit referenced in the uses clause.
I've tried:

  • Doing exactly what this code says.
  • Placing this code in the initialization section of the form that uses the unit that uses the external functions.
  • Placing this code in the initialization section of the unit that uses the external functions.

And by external functions I'm referring to a function that looks like:

function MyFunction: Integer; stdcall; external 'fundll.dll';

The problem I'm getting is the usual 'fundll.dll' cannot be loaded (because it's not in the directory) . Zarko's code works (pretty sweet, it creates the dll in that folder) when the code gets that far. But it just crashes before the project even gets rolling when I'm using the external functions I need.

like image 351
Peter Turner Avatar asked Dec 13 '22 04:12

Peter Turner


2 Answers

You can't do this with external functions - use LoadLibrary() and GetProcAddress() instead after extracting the DLL, and everything should work.

The reason is that any code will be executed only after all entry points have been resolved by the OS loader. Kind of a chicken and egg problem, if you will.

like image 92
mghie Avatar answered Mar 15 '23 02:03

mghie


If you are going to use LoadLibrary() and GetProcAddress(), you might prefer to use BTMemoryModule, which would allow you to use the DLL embedded as a resource without saving it to the filesystem (which the user might not be able to do, depending on the machine's security).

http://www.jasontpenny.com/blog/2009/05/01/using-dlls-stored-as-resources-in-delphi-programs/

like image 24
jasonpenny Avatar answered Mar 15 '23 02:03

jasonpenny