Tuesday, July 31, 2007
Binary (dll or exe) not linking to MSVCRxx.DLL and MSVCPxx.DLL
Are you having dll linkage hell. Is Dependency Walker (depends.exe) not finding the dlls linked to your module?(exe or dll).
Another symptom of this problem is getting a FileNotFoundException or an HResult:0x8007007E exception - for example:
Unable to load DLL 'xxxx.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
The issue of Dependency Walker not finding MSVCRxx.DLL and MSVCPxx.DLL, even though they are installed on your machine, could simply be the fact that a manifest file was not found for the binary. Check in your build output folder if one was created and copy it to the folder where your binary is - reopen Dependency Walker - and the dlls should be found. If not try reinstalling the libraries or make sure they are in the location that they are supposed to be in.
(note: The issues discussed in this post are specific to binaries built against .NET 2.0 or higher and VS2005 and higher as Manifests were first introduced with .NET 2.0 and Visual Studio 2005.)
One complication with the manifest file is that it could be embedded inside the binary - do the following:
1. Open the binary in Visual Studio and browse through the resources of the binary.
2. There should be a resource named RT_MANIFEST.
3. If you cannot find a resource by that name, then its not embedded. So check for an external file named binary_file_name.extension.manifest.
The manifest of an exe or dll is used to manage the names and versions of shared side-by-side assemblies to which the application should bind at run time (the MSVCRxx.DLL and MSVCPxx.DLL are CRT libraries found in the WinSxS folder).
Microsoft recommends that the manifest be embedded into your binary, that way if you forget to deploy the manifest file - this issue will not occur. View this page to find out how to embed the manifest file: How to: Embed a Manifest Inside a C/C++ Application
Learn more about manifests from this page: Understanding Manifest Generation for C/C++ Programs
Manifest Generation in Visual Studio: has information regarding how VS handles manifest generation.
Finally the page on Troubleshooting C/C++ Isolated Applications and Side-by-side Assemblies, has some excellent step by step tips on trying to debug DLL hell issues with C/C++ dlls.
Update:
What do you do if the CRT dlls (msvcr80.dll, msvcm80.dll, etc) are not on your machine: http://therajahs.blogspot.com/2007/08/vcredistexe-msvcr80dll-msvcm80dll.html
Labels:
.NET,
Code Sample,
VC++
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment