❔ COM type library integration in C++ project
Hi everyone.
I've made a dummy .net COM type library and I'm trying to integrate it in an equaly dummy C++ project. The project compile and link, but I have an
_com_error
exception at runtime : Error in DLL
.
Here's the library code:
14 Replies
and here's the C++ code:
I have no knowledge of either C# or .net, I am a C++ dev
I'm completly lost
Have you configured your project to register the component?
https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/w29wacsy(v=vs.100)
yessir
and the dll seems registered; when it wasn't I had a "class not registered" exception
this isn't the case anymore
I've tryed to manually registered it using
regasm
, but it didn't change anythingis COM your only option?
because you could just write a C shim and make this infinitely easier
can you send the Description of the _com_error instead
ErrorMessage is going to give an unspecific message
@RubyNova sadly yes. This is a library provided by a 3rd party.
@reflectronic I've missed that apparently, I'll try to do that
I've made a breakthrough yesterday. I figured that if I registered the dll manually (using regasm), I could in fact use the library.
now, I'm trying to figure out how to write a manifest file so I don't have to register the dll.
the _com_error Description() is
NULL
ok I just figured out what was going on
apparently there's 2 ways to use COm interropt : by registering the dll or by using the dll as a "register free" component
while the DLL was registered, my project was also configured (badly configured) to use it as a free component (as an isolated COM)
and since I don't have a manifest file, it fails
so here's what I've figured so far :
There's at least 2 ways to use COM interrop DLL.
1. by registering the DLL, which requires admin rights
2. by directly using the DLL (with the #using
instruction, which requires CLR enabled which means I'm limited to C++17
Is there any other way for me to use a COM dll in my (unmanaged) C++ project ?well, you can use reg-free by adding a manifest
but also, have you seen https://devblogs.microsoft.com/cppblog/cpp20-support-comes-to-cpp-cli/
Tanveer Gani
C++ Team Blog
C++20 Support Comes To C++/CLI - C++ Team Blog
Details of C++20 support for C++/CLI introduced in VS 2022 17.6
@reflectronic thank you
yes, that's what I've tried in 2.
problem is I use vs2019 and C++20
I can't downgrade to c++17
nor can I upgrade to vs2022
the manifest works great
I managed to use a small COM lib I've made
I have one last question on that topic :
Let say the COM lib A uses lib B
do I need to put lib B as a dependency of lib A in the manifest I generate for lib A ?
the manifest is for COM classes that you want to activate in your process (technically you can have isolated manifests, but, the point stands). if lib A is loaded into your process and needs to activate COM classes in lib B, then lib B either needs to be registered or its classes need to be in your manifest
if it’s just a regular library there’s no need. it’s strictly for COM classes
so, if lib A and lib B are both .NET libraries, lib A probably uses lib B just through an assembly reference (not through COM). there would be no need for lib B to be in your manifest. just the classes you activate from your unmanaged app
thank you very much
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.