This is a little bit difficult 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 float *points
and my C++ writes in that pointer.
Well, starting from the C++ part, I've written:
main_function.cpp this is my main function in C++ which works perfectly as 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 wrap my C++ code to C#, so I make the:
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 build it and it becomes in a AEDwrapper.dll
.
Now in Unity3D, in the C# part (script) I try 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 early steps from my code, but have you ever done that before??? I'm kind of lost.
Thank you in advance.
Rafael.
EDIT:
I've tried with a simple function (for example: int gimmetwo();
in the header and:
int gimmetwo() {
return 2;
}
and the result is the same :(
EDIT !!!! 11 July
After seeing answers like @k-gkinis and @nikola-dimitroff, I've understood that I have to compile different libraries for different environments.
In this case, I've created a 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 to 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 guess
What's wrong?