Use C++ API in C# Project

786 views Asked by At

Is it possible to use a C++ API (series of Header files and CPP files) in a C# project?

Maybe its possible to compile these files into .obj or .lib files and include them in the Visual C# project? Something similar is done for Crypto++.

If it is possible, are there any drawbacks from this?

Context and import information:

  • The C++ API is called NWCreate and is developed by Autodesk Navisworks
  • I am using Microsoft Visual Studio C# 2010
  • We have a large existing code base in C# where much of the operations we will perform in the navisworks plugin are already coded in C# (from other Autodesk projects we have produced). So having to rewrite all those operations in C++ is very much reinventing the wheel.
1

There are 1 answers

0
ray_linn On

at least , you have 2 method to invoke C/C++ API from .NET:

  • Compile the C/C++ API as dll, then use PInvoke to call it from .NET
  • Use Managed C++ (VC++), then use IJW to wrap the native code, IJW will generate managed code that can call directly from .NET