Class not registered error for creating C # object via COM from VC ++

In a VC ++ project, I'm trying to create an instance (via COM) of a C # class contained in a C # project.

Facts

  • C # and C ++ projects compiled using .NET 4.0
  • C # .dll is registered using regasm / codebase "CSharpProjectName.dll" "and Windows command line reports." Types successfully registered. "
  • In a C ++ project, I'm trying to create an instance of a class in a C # project, but I get HRESULT 0x80040154 - the class is not registered

Here is an example of my attempt to instantiate a .NET object from C # .dll. The specific class I'm trying to create is called Employee, which implements the IPerson interface for the sake of a simple presentation of my question:

CSharpProjectName::IPersonPtr pPersonPtr; HRESULT hr = pPersonPtr.CreateInstance(CSharpProjectName::CLSID_Employee); 

Why do I get the error "class is not registered" even if I registered C # .dll with "regasm / codebase" and confirmed that the key exists in the registry?

Any help would be greatly appreciated. Thanks!

+8
c # visual-c ++ com regasm
source share
3 answers

I had this problem in the past, and this was due to the fact that both processes were not 32 or 64 bits. If you are using a 32-bit OS, you can stop reading now because what I am saying does not apply.

Use regedit to try to find your ProgIds and CLSID in the registry. If your C ++ project is 32-bit, make sure your C # classes have been registered in the 32-bit hive - HKEY_CLASSES_ROOT \ Wow6432Node. If your C ++ project is 64-bit, make sure your C # classes have been registered in the 64-bit hive - HKEY_CLASSES_ROOT.

If you need to register with a 64-bit hive, you may need to call the version of RegAsm.exe in the c: \ windows \ microsoft.net \ framework64 directory ...

Another possibility to make a mistake is that you may need to run regasm.exe.NET 4.0. If you simply type "regasm" at the command line, this will give you the version of regasm that you are using. You may need to enter the full path of regasm version 4.0 4.0 - find it in the c: \ windows \ microsoft.net \ framework \ v4.0.3019 \ regasm.exe directory.

+9
source share

Have you tried the /tlb ? Try this and then

 #import "your_tlb_file_lol.tlb" no_namespace 

I think another option might be assembly, and then regasm it.

+1
source share

Try to leave the project 32 bits, because you know your project by creating an active component in any CPU that works with 32 with a registry error, so change the assembly to 32 or, preferably, 32.

You register dll too with regsvr32

0
source share

All Articles