尝试使用C ++代码中的c#类时,CoCreateinstance返回错误 [英] CoCreateinstance returns error while trying to use c# class from C++ code

查看:250
本文介绍了尝试使用C ++代码中的c#类时,CoCreateinstance返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用c ++代码中的c#assembly。为此,我已按照以下步骤操作。



在AssemblyInfo.cs中,我设置了属性ComVisible = true。

构建C#程序集后,我使用以下命令生成了类型库



RegAsm DLLNAME.dll / tlb



我已经在我的C ++程序中导入了生成的文件。



在我的TestApplication中一切正常。但是当我尝试将此c ++代码移动到我的MMC(Microsoft管理控制台)dll时,CoCreateInstance失败并显示错误代码 REGDB_E_CLASSNOTREG



为什么会这样,MMC的C ++ dll有什么特别之处?

I am trying to use c# assembly from my c++ code. For this i have followed these steps.

In AssemblyInfo.cs i have set the attribute ComVisible=true.
After building C# assembly, i have generated type library using following command

RegAsm DLLNAME.dll /tlb

I have imported the generated file in my C++ program.

In my TestApplication everything works fine. But when i try to move this c++ code to my MMC (Microsoft management console) dll, CoCreateInstance fails with the error code REGDB_E_CLASSNOTREG.

Why it is so, what is special about C++ dll for MMC ??

推荐答案

尝试通过/ codebase选项注册

RegAsm DLLNAME。 dll / codebase
Try to register by /codebase option
RegAsm DLLNAME.dll /codebase


这篇关于尝试使用C ++代码中的c#类时,CoCreateinstance返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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