如何将c ++ dll转换为.Net COM [英] How to convert c++ dll to .Net COM

查看:146
本文介绍了如何将c ++ dll转换为.Net COM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何将c ++ .dll文件转换为.Net COM。

我正在尝试添加VC ++(没有。 Net)项目进入我的.Net应用程序。

Hi,

How to convert c++ .dll file to .Net COM.
I am trying to add VC++(without .Net) project into my .Net Application.

推荐答案

不好主意。忘记COM,你不需要它。



相反,做两件事之一:1)使用P / Invoke从.NET应用程序访问非托管代码或者2)使用混合/模式(托管+非托管)C ++ / CLI项目来创建中间双可执行模块,您可以在.NET应用程序中将其用作.NET程序集和引用。



请参阅:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms632589%28v=vs.85%29.aspx [ ^ ]。



如果您需要学习P / Invoke,请从这里开始:

http://en.wikipedia.org/wiki/P/Invoke [ ^ ],

http://msdn.microsoft.com/en-us/library/Aa712982 [ ^ ]。



此CodeProject也很有用: Essential P / Invoke [ ^ ]。



现在,关于C ++ / CLI混合模式(托管+非托管)项目:



这样的项目可以构建全局钩子所需的DLL,但是它可以包含一些托管的包装器CLI代码,因此,从立场来看在.NET应用程序中,您可以将它用作常规.NET程序集,即引用它。请参阅:

http://en.wikipedia.org/wiki/C %2B%2B / CLI [ ^ ],

http://www.ecma-international .org / publications / standards / Ecma-372.htm [ ^ ],

http:/ /msdn.microsoft.com/en-us/library/xey702bw.aspx [ ^ ],

http:/ /msdn.microsoft.com/en-us/library/3bstk3k5 [ ^ ]。



请不要创建COM是为了在非面向对象的平台上使用OS API和模块化多语言应用程序时引入一些面向对象的特性。 .NET是一个强大的纯粹面向对象的平台。你不需要这种历史悠久的高度复杂的COM技术。



-SA
Bad idea. Forget COM, you won''t need it.

Instead, do one of the two things: 1) use P/Invoke to access unmanaged code from .NET Application, or 2) use mixed/mode (managed+unmanaged) C++/CLI project to create intermediate dual executable module which you can use as a .NET assembly and reference in your .NET application.

Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632589%28v=vs.85%29.aspx[^].

If you need to learn P/Invoke, start from here:
http://en.wikipedia.org/wiki/P/Invoke[^],
http://msdn.microsoft.com/en-us/library/Aa712982[^].

This CodeProject can also be useful: Essential P/Invoke[^].

Now, about C++/CLI mixed-mode (managed+unmanaged) project:

Such project could build a DLL required by the global hooks, but it can contain some managed wrapper CLI code, so, from the standpoint of your .NET application, you can use it as a regular .NET assembly, that is, reference it. Please see:
http://en.wikipedia.org/wiki/C%2B%2B/CLI[^],
http://www.ecma-international.org/publications/standards/Ecma-372.htm[^],
http://msdn.microsoft.com/en-us/library/xey702bw.aspx[^],
http://msdn.microsoft.com/en-us/library/3bstk3k5[^].

Please understand that COM was created to introduce some object-oriented feature in use of the OS APIs and modular multi-language applications on non-object-oriented platform. .NET is a strong purely object-oriented platform. You don''t need this historical highly convoluted COM technology.

—SA


这篇关于如何将c ++ dll转换为.Net COM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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