Search code examples
delphidllembedded-resource

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.


Solution

  • if you want to call a function in it, you have two choices ...

    1) use an exe/dll bundler instead of the resource method. 2) don't link to the library with the external style declaration. instead use LoadLibrary, GetProcAddress, etc to reference the function you need to call.

    the resource method and the declaration of the function as external will not mix. windows wants to link your exe to the dll in memory before your code runs to extract the dll.