I am working in with Makefiles in Cygwin in XP but using the Visual Studio 2005 commandline compiler. The unmanged code is written in C++ and the managed code is Managed C++.
I have a project that creates a bunch of unmanaged DLLs and one managed DLL. The managed DLL is a wrapper to one unmanaged DLL which then has references to many other unmanaged DLLs.
For example, -> Unmanaged / Managed --> Unmanaged --> Unmanaged \ -> Unmanaged, etc;
I have a managed code test driver that loads the Managed DLL, creates an object, and the makes calls to the Managed wrapper.
So here is the thing. As long as I leave all of the needed DLLs in the same directory as the test driver executable, everything works fine. But, I need to move the DLLs to a different directory than the test driver exe.
If I move everything to a different directory everything stop working. (I don't even get an error when I run test.exe, it "runs" then returns to the command line.) Obviously, this is a DLL issue.
开发者_C百科(Just so you know, I can't use GAC or %PATH% so that test.exe can locate the DLLs.)
So I did a lot of searching and have tried a variety of methods to figure out how to get test.exe to see the DLLs.
I tried Application Specified Paths. Didn't work. And the later read from http://msdn.microsoft.com/en-us/library/ms682586%28VS.85%29.aspx that "The App Paths key is not used when computing the DLL search path."
I tried all sorts of things with the manifest files.
I tried a bunch of things that most likely wouldn't have worked anyway but I was getting desparate.
And recently I have tried the app.config approach.
With this last approach I have had some success because test.exe runs but dies at runtime with an error when the test.exe tries to execute calls from the DLLs. Anything before then gets executed.
For example, if I run test.exe it asks the user for some information. If the information is bad then it returns an error back to the user, but if the information is correct it returns this error:
"Error: An ASCII parsing error occurred: Failed to load dynamic library [ATC15.dll].The specified module could not be found."
Then test.exe continues to execute the remaining code.
So please help me understand how I can get the executable to "see" all of the DLLs.
Hans made a good point. I have looked at the SetDLLDirectory (forgot to mention it) but I have never been able to get it to work. I always got the same results: execute program and nothing would happen.
However, I took his advice and reinvestigated the SetDLLDirectory function. I added:
#include "windows.h"
WINBASEAPI
BOOL
WINAPI
SetDllDirectoryA(
__in_opt LPCSTR lpPathName
);
#define SetDllDirectory SetDllDirectoryA
to the beginning of my code and then also a call to to SetDLLDirectory("c:\path"); and then recompiled. Ran the program and it still didn't work.
But then I added an app.config file to my directory
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="putDLLsHere"/>
<dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
That together it worked.
Thank you Hans for pointing me in the right direction!
精彩评论