This is a bit complicated because I donβt even know if my C ++ is well implemented.
I want to call a function from Unity3D, which I pass some parameters, such as float *points , and my C ++ writes in this pointer.
Well, starting with the C ++ part, I wrote:
main_function.cpp , this is my main function in C ++, which works fine as a binary, for example.
#include "main_function.h" extern "C" void getPoints (uchar *data, float *points, int rows, int cols, const char *trackername) { //load detector model face_tracker tracker = load_ft<face_tracker>(trackername); //create tracker parameters face_tracker_params p; p.robust = false; p.ssize.resize(3); p.ssize[0] = Size(21,21); p.ssize[1] = Size(11,11); p.ssize[2] = Size(5,5); Mat im = Mat(Size(cols, rows), CV_8U, data); if(tracker.track(im,p)) tracker.draw(im, points); }
main_function.h
#include "opencv_hotshots/ft/ft.hpp" #include "opencv2/highgui/highgui.hpp" #include <iostream> extern "C" { void getPoints (uchar *data, float *points, int rows, int cols, const char *trackername); }
Then I want to collapse the C ++ code in C #, so I do:
AEDwrapper.h
// AEDwrapper.h #pragma once #ifdef TESTFUNCDLL_EXPORT #define TESTFUNCDLL_API __declspec(dllexport) #else #define TESTFUNCDLL_API __declspec(dllimport) #endif using namespace System; #include "stdafx.h" #include "C:\Users\Rafael\Desktop\AEDlibrary\main_function.h" extern "C" { namespace AEDwrapper { TESTFUNCDLL_API public ref class AED { void getPointsAED (uchar *data, float *points, int rows, int cols, const char *trackername); }; } }
and AEDwrapper.cpp
// Archivo DLL principal. #include "stdafx.h" #include <ctime> #include <iostream> #include <chrono> #include <sys/timeb.h> #include "AEDwrapper.h" using namespace std::chrono; extern "C" { void AEDwrapper::AED::getPointsAED (uchar *data, float *points, int rows, int cols, const char *trackername){ getPoints(data, points, rows, cols, trackername); } }
I will build it and it will become in AEDwrapper.dll .
Now in Unity3D, in the C # part (script), I'm trying to do:
[DllImport ("/Assets/plugins/AEDwrapper.dll")] // or [DllImport ("AEDwrapper")] private static extern unsafe void getPointsAED (byte* data, float* points, int rows, int cols, sbyte* trackername); //DECLARA METODO DEL DLL
DllNotFoundException: /Assets/plugins/AEDwrapper.dll
I know I could be wrong in the early steps of my code, but have you ever done this before? I am lost.
Thanks in advance.
Raphael.
EDIT:
I tried a simple function (ex: int gimmetwo(); in the header and:
int gimmetwo() { return 2; }
and the result is the same: (
CHANGE !!!! July 11th
After looking at answers like @ k-gkinis and @ nikola-dimitroff, I realized that I had to compile different libraries for different environments.
In this case, I created Plugin.bundle for Mac OS x with:
Plugin.pch :
extern "C" { string getmytext(); }
Plugin.cpp
#include "Plugin.pch" string getmytext() { return "weowoewoeowoew"; }
I built it and I imported it into Unity3D:
[DllImport ("AED")] private static extern string getmytext (); static void obtenerPuntos() { Debug.Log (getmytext()); }
but I still get the same error!

The plugin is in the right place, I think

What's wrong?