C#COM dll在C ++项目中有REGDB_E_CLASSNOTREG错误 [英] C# COM dll has REGDB_E_CLASSNOTREG error in C++ project

查看:387
本文介绍了C#COM dll在C ++项目中有REGDB_E_CLASSNOTREG错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#dll,我已正确注册COM互操作,并使COM可见。使用cppbuilder,我导入了类型库,它生成了包装类,我现在尝试使用创建我的C#类的实例。但是,我得到一个REGDB_E_CLASSNOTREG错误在我的C ++代码。我验证了dll是在注册表中,甚至重新注册它与regasm。不用找了。

I have a C# dll that I properly have registered for COM Interop, and made COM visible. Using cppbuilder, I imported the type library, which generated the wrapper classes, and I am now attempting to use to create an instance of my C# class. However, I'm getting a REGDB_E_CLASSNOTREG error in my C++ code. I verified the dll is in the registry, and even re-registered it with regasm. No change. What could I be missing?

这是我的C ++代码:

Here is my C++ code:

_MyClassPtr obj;
HRESULT hr = obj.CreateInstance(__uuidof(MyClass));
//now hr equals REGDB_E_CLASSNOTREG



我也尝试过: p>

I've also tried it as such:

IMyClass* obj;
HRESULT hr = CoCreateInstance(__uuidof(MyClass), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMyClass), (void**) &obj);
//same result, hr equals REGDB_E_CLASSNOTREG

app。

更新:根据下面的注释,我发现CreateInstance正在查找注册表中以下位置的类别guid:

UPDATE: based on the comments below, I discovered that CreateInstance is looking up the class guid in the following places in the registry:

HKCU\Software\Classes\Wow6432Node\CLSID\{guid} 
HKCR\Wow6432Node\CLSID\{guid}
HKCU\Software\Classes\CLSID\{guid}
HKCR\CLSID\{guid}

但是,通过注册表,任何CLSID节点下的唯一条目与我的程序集相关的是程序集本身的guid,这当然不同于类或者接口的guid。

But, going through the registry, the only entry under any of the CLSID nodes that is related to my assembly is the guid for the assembly itself, which is, of course, different than the guid for the class, or the interface.

我手动在x86和x64模式下运行regasm以尝试获得不同的结果。没有差别。

I've manually run regasm under both x86 and x64 mode to try to acheive different results. No differences.

推荐答案

好吧,我发现了什么工作。

Well, I found out what would work.

IMyClassPtr obj;
HRESULT hr = obj.CreateInstance(CLSID_MyClass);

CLSID_MyCLass是生成的MyClass_TLB.cpp文件中的guid常量。使用它而不是__uuidof(...)为类类型启用一切开始正常工作。

CLSID_MyCLass was a guid constant in the generated MyClass_TLB.cpp file. Using it instead of __uuidof(...) for the class types enabled everything to start working correctly.

这篇关于C#COM dll在C ++项目中有REGDB_E_CLASSNOTREG错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆