i like import c++ dll in my c# application how can i Do this?, what is concept i need to use for this?
相关问题
- Sorting 3 numbers without branching [closed]
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- How to compile C++ code in GDB?
Have access to the C++ library source
The cleanest way is to use C++ Interop to create a wrapper as a mixed mode assembly. This allows you to use the pragmas managed and unmanaged to switch between native and managed code. This way you can nicely wrap your C++ class with a managed C++ wrapper and call it from (of course) managed C#.
Be aware this won't work under Mono.
Don't have access to the C++ library source, but know a bit of C++?
You can write a small managed wrapper in managed C++ to call the unmanaged C++ library due to C++'s unique ability to call COM natively.
This is done using custom runtime callable wrappers, or CRCWs. You can then call your managed wrapper directly from C# using native .Net types and all.
Benefits of this (as stated by MSDN):
Don't have access to the C++ library source and don't know C++?
Then you are stuck with C++ COM Interop which is a bit more messy. You'll need to generate a wrapper using Tlbimp.exe.
It's messy because:
You need to look at different kinds of interop. The easiest is P/Invoke. Then is is COM Interop. And then finally you can use Managed C++
suppose this DLL that compile with MinGW. in C-sharp you can follow this code:
This is the concept you need to use :)