Click here to Skip to main content
15,915,094 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have two dll's which are written in c++.It has enum ,method,properties etc..
I want to use them in c# application.
So what I should do?
Posted
Updated 2-Jul-12 23:24pm
v3

If this is purely native C++ (not C++/CLI), you can use only the method with P/Invoke. Please see:
http://en.wikipedia.org/wiki/P/invoke[^],
http://msdn.microsoft.com/library/en-us/vcmxspec/html/vcmg_PlatformInvocationServices.asp[^].

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

Sometimes you need much tighter integration. In this case, another approach could be beneficial: using C++/CLI and mixed-mode (managed + unmanages) project. Such project can use everything in C++ resources, as much as regular C++ could use, and all CLI types and members to the project, some of them wrapping unmanaged code. This way, you can create a class library using native C++, but used as a regular .NET assembly. You can reference this assembly as any other .NET assembly in your C# projects. Please see:
http://en.wikipedia.org/wiki/C%2B%2B/CLI[^],
http://www.gotw.ca/publications/C++CLIRationale.pdf[^],
http://www.ecma-international.org/publications/standards/Ecma-372.htm[^].

—SA
 
Share this answer
 
v3
See if this article in CP helps you:Dynamic Invoke C++ DLL function in C#[^]
 
Share this answer
 

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