Load tlb at runtime in C++ - c#

I have created a dll in C# which needs to be consumed by various C++ applications.
During installation of my product, I execute the regasm command to generate the .tlb file for my dll.
How can I load this tlb from my C++ application and call functions on it?

Related

How to add files to a Visual Studio C# solution, specific for each configuration - x86/x64/Debug/Release?

I'm writing a custom-action C# DLL that will be used from my WiX MSI installer. That DLL makes several pinvoke calls to another (unmanaged) DLL, which I need to include with my managed DLL (according to this post). I can do so by adding the unmanaged DLL to my C# project as a link from its compilation folder (from its C++ project in Visual Studio.)
The question is how do I add it depending on the bitness of the C# project and its type: x86 vs x64 and debug vs release?
For instance, when I build my custom-action C# DLL as x64, I need to include the 64-bit build of the unmanaged DLL. But when I build it as x86, I need a different version of the unmanaged DLL.

Using Registration-Free COM Interop with a C# .NET DLL without codebase/GAC?

I have a C# .NET DLL that is exposed through COM Interop for which I have generated a manifest file. The DLL is being consumed through an Excel VBAProject using CreateActCtx and CreateObject to create my objects.
Everything works fine, however... I need to call regasm MyProject.dll /codebase or register with GAC. Otherwise I get ActiveX component can't create object or error in dll errors.
Is it possible to use a .NET DLL without having to register the DLL at all? I was able to do this previously with a VB6-based DLL and a manifest file.

C++ DLL in C# WinMobile 6.1 Project - 1c2 machine (Thumb) vs 14c machine (x86)

I am trying to import a few DLLs that have been compiled for 1c2 machine (thumb) into a WinMobile 6.1 C# Smart Device project.
However when i try to import them to my C# project I get "A reference to ... cannot be added", I can add DLLs that have been compiled for 14C machine (x86), my C# WinMobile project has Any CPU as it's setting, is it possible to import 1C2 machine DLLs or do I need these to be recompiled to 14C machine x86?
You can't do what you're trying to do. You can't just "add a reference" to a native DLL from managed code. "Add Reference" is specifically for adding managed references.
If you want to call your native DLL from managed code, you must write and call P/Invoke interop functions. Even then, you can only call publicly exported C functions (not C++, unless it has a COM interface), so you may also have to write C stubs, or some form of factory functions to proxy any C++ calls you wish to make.

Using COM dll in a C# Project

I have all COM dll generated from a C++ library project. I want to use it in my C# project. I guess, I should import the xxxLib.dll file from the C++ library project, and import it to my C# project. But this xxxLib.dll is not generated in my C++ project. But I could see that xxx.dll and xxx.tlb are generated
You just register the dll with regsvr32.
Then add a reference, go to the COM tab, and choose your COM dll.

statically linking multiple VC++ libraries to a C++/CLI dll

So I have this C# project that requires the use of some functions from a vc++ library. This vc++ library is then dependent on other vc++ libraries.
So in order to get this working, I created a c++/cli dll project that wrapped the main vc++ library. In the project linker settings, I just added the target vc++ library in the input field, and this resolved linker errors. I then added a reference to the cli project to the c# project references.
Everything compiled fine, but when I ran the C# project, there was a File.IO.Exception saying that the cli dll couldn't be loaded. After some tinkering around, I found that this error was happening because the wrapped vc++ dll dependencies could not be loaded. So I copied the vc++ dll into the same folder as the c# exe. I also had to copy all of the other vc++ dlls that the initial dll depended on.
Having to keep track of all of the VC++ dlls is burdensome, so I'm wondering if it is possible to statically link all of the VC++ dlls into the C++/CLI dll, so I do not have to copy them into the same folder as the C# exe. I tried adding all of the vc++ dependencies to the linker input field but that didn't do anything.
Thanks,
Alex

Categories