From: Dimitry K. <dim...@gm...> - 2007-04-17 17:06:37
|
Hello Here is my situation: I have a dll built with MinGW (gcc-3.4.2). This dll creates and runs an internal perl interpreter, thus, it has dependency on perl58.dll supplied with ActivePerl distribution. The dll is dynamically linked by third party application that I can't control. I am aware that more then one copy of perl58.dll may occur and I need to ensure that my dll will load the copy supplied by my distribution. The question is how I actually ensure this. Right now I have the following methods in mind: 1. Link with absolute path to perl58.dll. Not quite good since the exact location of the dll is defined in the installation time 2. On XP and Win2003 it is enough to put my dll and perl58.dll in the same directory. Works well, but I am still having problem on Win2000. Right now the only way to affect dll loading path is altering the PATH environment variable. My goal is to avoid using PATH because of security reasons. 3. Well, now the question: MSDN says that it is possible to affect the dll loading mechanism by embedding a manifest file as a dll resource. Does anybody have an example or reference to example of such an embedding? Is it possible with MinGW tools at all? Are there ways to solve my problem not listed above? Many Thanks -- Dimitry Kloper lt dimitry dot kloper at gmail dot com gt |
From: Brian D. <br...@de...> - 2007-04-17 17:28:54
|
> Dimitry Kloper wrote: > 1. Link with absolute path to perl58.dll. Not quite good since the > exact location of the dll is > defined in the installation time I'm pretty sure you can't embed the actual absolute path to a DLL when linking, just the name of the DLL. > 2. On XP and Win2003 it is enough to put my dll and perl58.dll in the > same directory. > Works well, but I am still having problem on Win2000. Right now the > only way to affect > dll loading path is altering the PATH environment variable. My goal is > to avoid using PATH > because of security reasons. Look at the MSDN docs for LoadLibrary for the details on all the things that affect the DLL search order. > 3. Well, now the question: MSDN says that it is possible to affect the > dll loading mechanism by > embedding a manifest file as a dll resource. Does anybody have an > example or reference to > example of such an embedding? Is it possible with MinGW tools at all? Sure, just create your XML manifest file, then reference it in your resource file, e.g.: #include "windows.h" ... CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "foo.exe.manifest" ... Then compile the .rc file into an object file (.o) with windres: %.o: %.rc $(WINDRES) -o $@ $< And just add that object to the link command. If you need examples of the .rc syntax, it's all documented on MSDN and/or the PSDK and you can use the format almost verbatim. Brian |