This is done via P/Invoke. You need to make a DLL using C++ code, exports functions you need. You cannot and need not to add this DLL to your C# project. Instead, you should create some class with static declaration of the functions exported from your DLL and apply
System.Runtime.InteropServices.DllImportAttribute
. If you do it correctly, you DLL will be referenced in you managed code. See for help and code samples:
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx[
^].
This can be a bit tricky due to different types. You should use how to learn
System.Runtime.InteropServices.MarshalAsAttribute
, sometimes
InAttribute
,
OutAttribute
or
OptionalAttribute
, see
http://msdn.microsoft.com/en-us/library/9esea608.aspx[
^] and the references.
Alternative way is using mixed-mode (managed+unmanaged) C++ project, where you can mix C++ and C++/CLI code. This is the way to wrap C++ declarations into C++/CLI managed type and make them accessible for any .NET assembly. In this way, you can reference this DLL as a normal .NET assembly.
[EDIT]
After changes in Microsoft documentation, most adequate link to P/Invoke and C++/CLI
implicit P/Invoke is this:
https://msdn.microsoft.com/en-us/library/ms235282.aspx[
^].
—SA