Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ DLL
HI ,
I want to use a C++ dll in C#.Net application.How can i use C++ dll in my code. if i can use more than one way which is the best way to use C++ dll .
Thanks in Advance
Posted 7-Feb-13 18:33pm
Argonia at 8-Feb-13 8:46am
if its only for calling methods you can just add it in the References.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There are several ways of doing it.
Create C++/CLI wrapper around your C++ native code (make static library out of C++ native code) and C++/CLI generated assembly can be easily utilized in .net application.
COM, i.e using interop (which is difficult among all the options)
In my suggestion easiest way is to use option 2, but you need to take care of proper marshaling.
H.Brydon at 8-Feb-13 14:25pm
Good info, but you left out P/Invoke, which in my experience is the most used mechanism.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

P/Invoke can be used to call stand-alone functions from native DLLs. But if you want to use entire classes, when you should go with another approach. The best would probably be to write a C++/CLI wrapper over your native code and expose the desire functionality to the managed application. Another approach, though I find it harder, is to write a COM wrapper around your native DLL. This COM object can then be consumed from your managed application.

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

  Print Answers RSS
0 Richard MacCutchan 335
1 OriginalGriff 310
2 Sergey Alexandrovich Kryukov 239
3 Sharmanuj 146
4 Magic Wonder 129
0 Sergey Alexandrovich Kryukov 5,999
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505

Advertise | Privacy | Mobile
Web01 | 2.8.140814.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100