-3

I have an existing codebase of C++/CLI calling C# and want to drive both of these from VBA. The C# code is called from the C++/CLI and works great if I run it all using a simple C++ exe. The problem is, I am now trying to invoke the C++/CLI (and subsequent C#) from VBA. My code successfully finds the C++/CLI .DLL, but won't complete the subsequent call into C#! On inspection it appears that the C# .DLL is not being found by the C++/CLI... Both the C++/CLI .dll and C# .dll reside in the same folder (not in the excel.exe folder).

In the VBA code I have tried loading both dll's using "LoadLibrary" and an absolute path. It appears to work in VBA debugger (handles are returned for both dll's) but if i debug using visual studio it appears that my C# .dll is not loaded properly. On the modules window I have a message saying "library not loaded from the specified load directory" or (something synonymous to that) for my C# .dll. Could this be because my C# .dll is compiled as an assembly? Is there a different loading method required for this type of library?

Note that I cannot register C# .dll for COM interop, nor can I put it in the same folder as the excel.exe. Anything that requires admin rights here is completely off limits.

In the VBA code I have tried loading both dll's using "LoadLibrary" and an absolute path. It appears to work in VBA debugger (handles are returned for both dll's) but if I debug using visual studio it appears that my C# .dll is not loaded properly. On the modules window I have a message saying "library not loaded from the specified load directory" (or something synonymous to that) for my C# .dll. Could this be because my C# .dll is compiled as an assembly? Is there a different loading method required for this type of library?

I have also tried Assembly LoadFile in my C++/CLI layer rather than using a reference in the project but that hasn't got me anywhere.

This all works fine when invoked from a C++ application exe in the same folder as the dll's.

  • Note you don't necessarily need admin rights to perform COM registration, E.,g. https://stackoverflow.com/questions/35782404/registering-a-com-without-admin-rights. – Alex K. Feb 27 '23 at 13:42
  • fuslogvw.exe can help diagnose binding problems. – Alex K. Feb 27 '23 at 13:42

1 Answers1

-2

Fixed this problem using Assembly::LoadFile and invoking methods in the C#.

ChrisF
  • 134,786
  • 31
  • 255
  • 325