Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

How to convert c++ .dll file to .Net COM.
I am trying to add VC++(without .Net) project into my .Net Application.
Posted
Comments
Jochen Arndt 18-Dec-12 7:40am    
Please don't repost. You may edit your first post for clarification or additional information.
Richard MacCutchan 18-Dec-12 9:19am    
Short answer, you can't. You need to write a COM wrapper which provides a COM interface to your VB.NET application, and passes requests through to the DLL on the other side. P/Invoke would be much simpler.
Sergey Alexandrovich Kryukov 18-Dec-12 20:16pm    
Exactly. I answered in detail, please see.
—SA
Sergey Alexandrovich Kryukov 18-Dec-12 19:42pm    
Why?!
—SA

1 solution

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
 
Share this answer
 
v3
Comments
Wendelius 22-Dec-12 3:54am    
Good answer, 5.
Sergey Alexandrovich Kryukov 22-Dec-12 20:05pm    
Thank you, Mika.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900