1

I'm in DLL hell. I have 2 DLLs let's say A.dll and B.dll which have a name collision - the same C++ class name is used in each, etc. Both DLLs are available as static libs.

Can I create a 'wrappe' DLL, say Aprime.dll which exports a similar class, methods, etc. as in A.dll, and delegates the functionality to the class in A.lib, but statically linked into the Aprime.dll? Wouldn't that avoid the name collision?

I've been trying this, but not sure I have the MSVS project set up correctly. Aprime.dll is being produced, but according to Dependency Walker Aprime.dll is still loading A.dll.

I've been searching, but most stuff I find applies only to statically linking in the CRT or MFC, which have their own switches.

I added A.lib under Linker -> Input -> Additional Dependencies.

Am I missing some magic linker command line switch or something?

Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
Captain Aporam
  • 315
  • 1
  • 4
  • 13

2 Answers2

0

Yes that method should work. The key though is to ensure that you do not include any of the original A.dll header files in the Aprime.dll header file. Otherwise if someone includes Aprime.h/pp then it will include A.h/pp and you will then have a clash again.

So you want something like:

A.h

// Library A includes
class test
{
};

B.h

// Library B includes
class test
{
}

Aprime.h

// Proxy class
class myTest
{
}

Aprime.cpp

#include "A.h"
#include "Aprime.h"

...

main.cpp

#include "Aprime.h"
#include "B.h"

...

Note that main never includes both A and B. In only includes Aprime and B. B is still static lib and Aprime is a DLL.

Chris
  • 2,655
  • 2
  • 18
  • 22
  • So it could work, then I must be doing something wrong, since my Aprime.dll is loading A.dll - it shouldn't, if A.lib were statically linked into Aprime.dll. – Captain Aporam Jun 09 '15 at 17:09
  • Are you sure the .lib you are using is a static library and not the loader stuff for the .dll instead? – Chris Jun 09 '15 at 17:14
  • Chris, how do I verify or confirm that? I've added the .lib, is that all I need to do? – Captain Aporam Jun 09 '15 at 17:17
  • I've never needed to check, if I did I would just create a console app, include the lib and then see if it runs. If it complains about .DLL missing, then its a lib version. I did find this post though: http://stackoverflow.com/questions/6402586/know-if-lib-is-static-or-import – Chris Jun 09 '15 at 17:25
  • I used that lib tool you suggested in that link, and I'm using an import lib not a static lib. I can't get a real static lib, I think I'm hosed. But thanks for your help. – Captain Aporam Jun 09 '15 at 17:57
  • The solution for me then would be to include the import lib into Aprime and then, make the interfaces to Aprime accessible by C function factory. Then return from the factory function, Aprime class objects. This way you can skip the inclusion of Aprime import library completely and instead use LoadLibrary GetProcAddress to acquire access to Aprimes factory function and call it to get access to Aprime classes. Internally the clases use A. This will remove the clash. – Chris Jun 09 '15 at 18:28
0

Yes, you can, and it's supported at a very low level by Windows. Aprime.DLL is effectively empty except for a bunch of references to A.DLL.

MSalters
  • 173,980
  • 10
  • 155
  • 350