在MFC应用程序中使用C#dll作为COM [英] Using C# dll as COM in an MFC application

查看:62
本文介绍了在MFC应用程序中使用C#dll作为COM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我在VS2005中编写了一个C#dll。

使用Interop Services导出一个接口和类。

我想要在我的MFC应用程序中使用此c#dll,使用VS2003。

我将dll导入到我的MFC应用程序后编译。

在运行时我得到类没有注册HR错误在我的MFC项目中。


我使用的代码如下:

_NewActivationPtr myActivation = NULL;


HRESULT hr = myActivation.CreateInstance(__ uuidof(NewSupernaAct ivation));


我不该做什么。


我必须使用GACUtil注册?


如果我想使用GACUtil我是否必须签署我的项目?


尝试这样做失败了,因为我在我的C#

dll中使用的第三方库没有签名(所以如果我选择签署我的项目,有一个编译

错误,因为我认为第三方图书馆没有签名。


请帮忙,

谢谢,


Janiv Ratson。

Hello,
I have written a C# dll in VS2005.
One interface and class are exported using Interop Services.
I want to use this c# dll in my MFC application, using VS2003.
It compiles after I imported the dll to my MFC app.
On runtime I get class not registered HR error in my MFC project.

I use the code as follow:
_NewActivationPtr myActivation = NULL;

HRESULT hr = myActivation.CreateInstance(__uuidof(NewSupernaAct ivation));

I don''t what to do.

Do I have to use GACUtil to register?

If I want to use GACUtil do I have to sign my project?

Trying do it had failed, because my third party library I''m using in my C#
dll is not signed (so if I choose to sign my project, there is a compilation
error, caused because the 3rd party library is not signed, I guess).

Please help,

Thanks,

Janiv Ratson.

推荐答案

" ; Janiv Ratson < janivr @ gmailcomwrote in message

news:uE ************** @ TK2MSFTNGP03.phx.gbl ...
"Janiv Ratson" <janivr@gmailcomwrote in message
news:uE**************@TK2MSFTNGP03.phx.gbl...

我在VS2005中编写了一个C#dll。

使用Interop Services导出一个接口和类。

我想在这个c#dll中使用我的MFC应用程序,使用VS2003。

我将dll导入到我的MFC应用程序后进行编译。

在运行时,我的MFC项目中没有注册HR错误。
I have written a C# dll in VS2005.
One interface and class are exported using Interop Services.
I want to use this c# dll in my MFC application, using VS2003.
It compiles after I imported the dll to my MFC app.
On runtime I get class not registered HR error in my MFC project.



我不确定它是否会有所帮助,但我发布了一个使用

托管程序集的分步示例作为来自本机代码的COM对象:

http://groups.google.com/group/micro...153307ba483255


问候,


I''m not sure if it will help, but I posted a step-by-step example of using a
managed assembly as a COM object from native code here:

http://groups.google.com/group/micro...153307ba483255

Regards,
Will




除了DePalo的帖子,看看最新的MSDN

杂志,还有一篇关于这个精确主题的文章。

-

-

Ignacio Machin,

ignacio.machin at dot.state.fl.us

佛罗里达州交通局


" Janiv Ratson" < janivr @ gmailcomwrote in message

news:uE ************** @ TK2MSFTNGP03.phx.gbl ...
Hi,
In addition to DePalo post take a look at the latest number of MSDN
magazine, it has one article about that precise subject.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Janiv Ratson" <janivr@gmailcomwrote in message
news:uE**************@TK2MSFTNGP03.phx.gbl...

您好,

我在VS2005中编写了一个C#dll。

使用Interop Services导出一个接口和类。

我想在我的MFC应用程序中使用这个c#dll,使用VS2003。

我将dll导入到我的MFC应用程序后编译。

在运行时我上课我的MFC项目中没有注册HR错误。


我使用的代码如下:

_NewActivationPtr myActivation = NULL;


HRESULT hr = myActivation.CreateInstance(__ uuidof(NewSupernaAct ivation));


我不该做什么。


我是否必须使用GACUtil进行注册?


如果我想使用GACUtil我是否必须签署我的项目?


尝试这样做失败了,因为我在我的C#

dll中使用的第三方库没有签名(所以如果我选择签署我的项目,那么ere是一个

的编译错误,因为第三方库没有签名,我猜了b $ b猜。)


请帮忙,


谢谢,


Janiv Ratson。

Hello,
I have written a C# dll in VS2005.
One interface and class are exported using Interop Services.
I want to use this c# dll in my MFC application, using VS2003.
It compiles after I imported the dll to my MFC app.
On runtime I get class not registered HR error in my MFC project.

I use the code as follow:
_NewActivationPtr myActivation = NULL;

HRESULT hr = myActivation.CreateInstance(__uuidof(NewSupernaAct ivation));

I don''t what to do.

Do I have to use GACUtil to register?

If I want to use GACUtil do I have to sign my project?

Trying do it had failed, because my third party library I''m using in my C#
dll is not signed (so if I choose to sign my project, there is a
compilation error, caused because the 3rd party library is not signed, I
guess).

Please help,

Thanks,

Janiv Ratson.



Janiv,


您是否检查了注册表以确保实际注册的COM接口是否为



运行Regedit.exe,然后搜索NewSupernaActivation或您的

DLL的名称。如果你找不到,那么它就没有注册,这就是你的问题。

你需要运行regasm.exe注册DLL。


Kim


-

digipede - 许多腿轻松工作。

网格计算真实世界。
http://www.digipede.net
< a rel =nofollowhref =http://krgreenlee.blogspot.nettarget =_ blank> http://krgreenlee.blogspot.net
Janiv,

Did you check the registry to make sure that the COM interfaces were
actually registered?

Run Regedit.exe and then search on NewSupernaActivation or the name of your
DLL. If you don''t find it then it''s not registered and that is your problem.
You''ll need to run regasm.exe to register the DLL.

Kim

--
digipede - Many legs make light work.
Grid computing for the real world.
http://www.digipede.net
http://krgreenlee.blogspot.net


这篇关于在MFC应用程序中使用C#dll作为COM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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