1

I am trying to reference a .Net DLL(call it B.dll), which basically is a wrapper for a .Net third party(call it C.dll), into c++ MFC project. I did create the tlb file for B.dll and am able to instantiate and call this within the MFC app.

At the moment all the dependencies, B.tlb, B.dll and C.dll, need to be in the bin folder of the MFC application. What I want, and am struggling to do, is to put these three files in a sub folder of the MFC execution folder.

I tried setting the "privatePath" of the B.dll config file to a sub folder but as I understood it, it's not the B.dll "privatepath" that needs to be set but the MFC application(which obviously hasn't got any as far as I know, as it's not a .Net application)

Any help is appreciated.

ali
  • 529
  • 4
  • 26
  • 1
    You are certainly maximizing DLL Hell in this scenario, there is never much point to that. The CLR looks for a somename.exe.config file in the same directory as somename.exe. So you can add a `` element to help it find the C.dll file. B.dll can only be found by using the /codebase option in the Regasm.exe command that you need to use to register the assembly or by giving the mfc app a manifest with a `` element. Using the GAC on the user's machine for COM dependencies is never a bad idea. – Hans Passant Apr 26 '16 at 17:39
  • Why this scenario is considered as DLL hell? Could you explain it more please? as I can't think of doing it without making a .Net dll wrapper and to register it as a COM component. – ali May 09 '16 at 12:49

1 Answers1

0

You don't need to use COM (if you need it my answer is obsolet).

You can write your own C++/CLI wrapper DLL that has just exports a native interface. Than call you can this native wrapper and this wrapper again loads your .Net component directly and executes the code in it.

In this wrapper DLL you can add an ResolveEventHandler where you implement your own search (maybe in the subdirectory). Add this to your CurrentDomain->AssemblyResolve

With this trick you get around all this COM stuff, and you have full control were assemblies should be searched for that can't be loaded.

I have the solution from here

Community
  • 1
  • 1
xMRi
  • 14,982
  • 3
  • 26
  • 59