6

I have a third-party DLL that depends on MSVCR80 and allocates resources that I need to cleanup. The library does not expose a free-function for doing this. Instead, I need to load the same runtime library and manually call the free function.

As a workaround I'm trying to write a "wrapper" DLL that loads the correct runtime and exposes the free function. This DLL is created using Visual Studio 2010 and is dependent on a separate runtime library. Doing LoadLibrary("msvcr80.dll") fails with error R6034 which I guess is because of manifest issues.

Is it even possible to load msvcr80.dll using LoadLibrary? Do I need to create a manifest, embed it into the DLL and store msvcr80.dll in the same directory as my wrapper DLL?

I realize that this is a flaw in the third-party library, but I'm pretty much stuck with this version. Getting the vendor to fix this is most likely not an option.

larsmoa
  • 12,604
  • 8
  • 62
  • 85
  • 1
    See if these links help: http://cowwoc.blogspot.com/2008/09/fixing-visual-studio-run-time-error.html, http://msdn.microsoft.com/en-us/library/ms235342%28v=vs.80%29.aspx – paulsm4 Sep 14 '11 at 16:21
  • 1
    Use the activation context api with the same manifest resource that is used by the miscreant dll. That will make the LoadLibray call work. – David Heffernan Sep 14 '11 at 16:38
  • 2
    You need GetModuleHandle() instead since the DLL is already loaded. Then GetProcAddress() to get the address of the _free function. – Hans Passant Sep 14 '11 at 16:42
  • @hans the problem is what to pass as the module name. It's that lovely SxS thing. See the previous question. – David Heffernan Sep 14 '11 at 16:45
  • @David - only the SxS directory name is complicated, an issue for LoadLibrary. Not for GetModuleHandle, the module name is simply "msvcr80". – Hans Passant Sep 14 '11 at 17:10
  • @hans you should write that as an answer – David Heffernan Sep 14 '11 at 17:28
  • @larsm I've taken Hans' idea and applied it to your previous question. I presume you are still ultimately doing this through ctypes and Python. I think this means you don't need the C++ wrapper DLL that you are describing in this question. I've tested it out and it should all work beautifully from ctypes. – David Heffernan Sep 14 '11 at 17:58

1 Answers1

3

Probably there are better solutions, but in case everything else failed you could find somewhere a copy of VC++ 2005 Express Edition (=free, no piracy is needed ;) ), which uses the version 8.0 of the compiler, and thus the same runtime of the defective dll.

Then you would build your wrapper dll with it, which would just call the free provided by its CRT (double check that you're using the dll version!).

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
  • VC++ 2005 Express is only free if you get it directly from Microsoft, and I don't think they offer it any more. Just because it was free doesn't mean it wasn't copyrighted, and nobody else has the rights to distribute it. – Mark Ransom Sep 14 '11 at 17:08
  • I wasn't aware of that licensing restriction, still the 8.0 compiler should still be around in various packages still available on MS site (I recall it was used in the last DDK before they were renamed WDK). – Matteo Italia Sep 14 '11 at 17:23
  • Good idea and I would probably have ended up doing (something like) this, if I hadn't found another solution to my initial problem (see http://stackoverflow.com/questions/7399774/using-ctypes-to-load-a-specific-runtime-library-msvcrt80 for details about the problem+solution I was working with). – larsmoa Sep 15 '11 at 09:01