Development environment:
Visual Studio 2013+win10
One: Building C + + projects
To build C++project (Win32 project) in VS, be aware that you want to tick:
Application Type:dll
Additional Options:export Symbols
Put the code in the project header file:
#define WAOCVDLL_API __declspec (dllexport)//custom method Extern_c Waocvdll_api int _stdcall Fit (int width, int height, wchar_t*i Mage, Float*firstpoint, int pointslength);
Then implement the method in the CPP file:
Waocvdll_api int _stdcall Fit (int imagewidth, int imageheight, wchar_t*image, float*firstpoint, int pointslength) {//implementation code }
Ps:waocvdll_api different for each project
You need to set the project properties before compiling:
Compile As:compile as C + + code
The platform structure of the Ps:c++ project must be consistent with the invocation of the project (if x64 is x64 and vice versa).
Ok,build project, get DLL
Two: Build the Calling Project (C # Console)
What you should be aware of when calling:
[DllImport (@ "Your DLL storage path", EntryPoint = "method name defined in C + +")]extern static unsafe int Fit (int width, int height, char* image, Floa t* firstpoint, int pointslength);
After that, the unmanaged code is called in C #, and it is important to note that:
1. Set project properties: Allow unsafe code
2. Add unsafe code blocks to your code
OK, run the console project, the project is working properly!
C # calls the C + + export (dllexport) method