How can I add a C++ DLL file in my .NET application?
Asked
Active
Viewed 2,244 times
4 Answers
6
You would use an "extern" function, marked with the DllImport attribute.
[DllImport(@“C:\mylib.dll”)]
public static extern int myFunc(int param);
John Gietzen
- 47,524
- 30
- 142
- 185
0
If it's registered in COM, you can simply add a COM reference in Visual Studio and Visual Studio will do all the Interop creation for you.
Peter Mortensen
- 30,030
- 21
- 100
- 124
Steve Danner
- 21,452
- 7
- 39
- 51
0
Assuming you use Visual Studio, in your Solution right click "references" and choose "Add Reference". Select your dll file.
In the classes that will use the dll, add : using MyLibrarysName;
then you can call the functions in that DLL using Mylibraryname.myfunction
Roast
- 1,685
- 4
- 23
- 32
-
Yeah... thats exactly how to do it in simple step by step instructions. I dont understand why anyone would vote that down. +1 – StingyJack Feb 08 '10 at 18:17
-
If the DLL is a C++ dll, add reference doesn't allow to add this reference. The error report says: "A reference to '
'could not be added. Please make sure that the file is accessible and that it is a valid assembly or COM component.' The standard C++ value doesn't have an assembly, nor is it a COM component – Harald Coppoolse Jun 19 '14 at 14:55