I have been writing a basic dll in c++ with the end-goal of accessing some of it's methods in Unity. I started this tutorial in : http://docs.unity3d.com/Documentation/Manual/Plugins.html which helped me understand the concept but after I write the class in Unity and access the .dll it throws me an entry point exception error when I hit play. And yes, I have a plugin folder where i keep my .dll file.
EntryPointNotFoundException: addition PluginImport.Start () (at Assets/Test/PluginImport.cs:20)
Here is my .dll class.
The Header File:
#ifndef MATHASSISTANT_ARITHMETICS_ARITHMETIC_H
#define MATHASSISTANT_ARITHMETICS_ARITHMETIC_H
namespace ma{
extern "C"
{
class Arithmetic
{
public:
Arithmetic();//ctor
protected:
virtual ~Arithmetic();//dtor
public:
static __declspec(dllexport) float addition(float& val_1, float& val_2);
static __declspec(dllexport) float substraction(float& val_1, float& val_2);
static __declspec(dllexport) float multiplication(float& val_1, float& val_2);
static __declspec(dllexport) float division(float& val_1, float& val_2);
};
}
}
#endif
This is the source file:
#include "Arithmetic.h"
#include <stdexcept>
namespace ma{
Arithmetic::Arithmetic(){
//TODO: Initialize items here
}
Arithmetic::~Arithmetic(){
//TODO: Release unused items here
}
//FUNCTION: adds two values
float Arithmetic::addition(float& val_1, float& val_2){
return val_1 + val_2;
}
//FUNCTION: substracts two values
float Arithmetic::substraction(float& val_1, float& val_2){
return val_1 - val_2;
}
//FUNCTION: multiplies two values
float Arithmetic::multiplication(float& val_1, float& val_2){
return val_1 * val_2;
}
//FUNCTION: divide two values
float Arithmetic::division(float& val_1, float& val_2){
if(val_2 == 0)
throw new std::invalid_argument("denominator cannot be 0");
return val_1 / val_2;
}
}
This is the class I created in Unity3D:
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
public class PluginImport : MonoBehaviour
{
//Lets make our calls from the Plugin
[DllImport("Arithmetic")]
private static extern float addition(float val_1, float val_2);
[DllImport("Arithmetic")]
private static extern float substraction(float val_1, float val_2);
[DllImport("Arithmetic")]
private static extern float multiplication(float val_1, float val_2);
[DllImport("Arithmetic")]
private static extern float division(float val_1, float val_2);
void Start()
{
Debug.Log(addition(5, 5));
Debug.Log(substraction(10, 5));
Debug.Log(multiplication(2, 5));
Debug.Log(division(10, 2));
}
}
If anyone can help me find what I am doing wrong I will be most appreciative. Thanks in advance!