Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI C#
Hi,
 
I have a SDK .lib which is written on native C++. I want to write a C# application to use the functions available in the native C++ library.
As I found in the net The solution is in the following way, correct me If I am wrong
 
1. Need to write a wrapper function for that .lib file using C++/CLI file and creat a DLL.
 
2. Refer this DLL from C# application & achieve the result.
 
Please confirm the above way is right ? If yes can we write a wrapper through VC++ / do we need to write only through C++/CLI ?
 
Need some sample on writing a wrapper function on C++/CLI .
 
Thanks,
Pattabi
Posted 22-Jan-10 1:56am
rprtech268
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

rprtech wrote:
1. Need to write a wrapper function for that .lib file using C++/CLI file and creat a DLL.

 
This is true. You will need to create a new managed class library in C++ (New > Project > Visual C++ > CLR > Class Library). In this class library you will need to add a reference to the .lib file. Finally, you will have to define and create a "public ref class" that wraps the functionality of the unmanaged code. Don't forget to add the include path of the header file that defines the .lib function.
 
rprtech wrote:
2. Refer this DLL from C# application & achieve the result.

 
To reference the C++/CLI class from C# you can add a reference the C++ project. I also like to have both projects in the same solution. You can also build the C++ DLL (class library) and refernce the DLL directly.
 
rprtech wrote:
Need some sample on writing a wrapper function on C++/CLI .

 
Just create a public method (static if you like) in your C++ ref class and in the body of the function call to the unmanaged code.
  Permalink  
Comments
BatulKaleem at 22-Jun-10 10:55am
   
My native project references a lot of libs. If I just add a reference to the native .lib, it still does not work. I have to put additional include directories as well as additional dependencies. Is that the correct way to do it?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Yes. You have to write an unmanaged DLL, and then use InteropServices in your managed assembly to get to the DLLs functionality.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
Thanks for your reply. Could you please give sample code/ link for it ?
  Permalink  
v2

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 6 Dec 2010
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