views:

220

answers:

2

Hey everyone,

I have a C# library that I am using for a COM object in unmanaged C++ code. I registered the library using Visual Studio's checkbox "Register For Com Interop" and set ComVisible to true.

imported the tlb to the C++ app..... when I run it, I get a "Class Not Registered"....

This has worked before, but this started happening after I moved the directory of my C# project to a different location.... yes I did re-register the library after I moved it.

I've removed all references from the registry... I 've even tried doing a gacutil.exe /i on it... no dice.

Anyone know how to fix this?

A: 

If you don't have explicit CLSID set on your managed object, it's possible that the move and rebuild has generated a new CLSID. Make sure your unmanaged project does not have a stale copy of the typelib.

Go to HKCR\CLSID\{XXXX} and ensure that the class registration for the managed object points to the right managed dll.

Franci Penov
I cleaned my solution in the unmanaged solution to make sure it was getting a new Type Library....By HKCR\CLSID, do you mean the GUID of the library?
DJ Burb
No, I mean the CLSID of your object - the one you are using when calling CoCreateInstance() from the unmanaged code.
Franci Penov
yeah, I checked that, the dll is in the correct location
DJ Burb
A: 

A better way of using unmanaged objects in managed code is to use C++ / CLI. You can easily create a managed wrapper around the native object.

Mark P Neyer
does it work the other way around? using a managed object in unmanaged code.
DJ Burb
you can also use C++ / CLI to wrap managed objects as native objects.
Mark P Neyer