Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found the answer. I had to do some tweaking to the code but basically I will show you:</p> <p>This is my MathHelper.dll</p> <p>Header: </p> <pre><code>#ifndef MATHASSISTANT_ARITHMETICS_ARITHMETIC_H #define MATHASSISTANT_ARITHMETICS_ARITHMETIC_H #include &lt;Windows.h&gt; #include &lt;WbemCli.h&gt; namespace ma{ extern "C" { class Arithmetic { public: Arithmetic();//ctor protected: virtual ~Arithmetic();//dtor public: BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID); __declspec(dllexport) float addition(float val_1, float val_2); __declspec(dllexport) float substraction(float val_1, float val_2); __declspec(dllexport) float multiplication(float val_1, float val_2); __declspec(dllexport) float division(float val_1, float val_2); }; } } #endif </code></pre> <p>The source file:</p> <pre><code>#include "Arithmetic.h" #include &lt;stdexcept&gt; namespace ma{ Arithmetic::Arithmetic(){ //TODO: Initialize items here } Arithmetic::~Arithmetic(){ //TODO: Release unused items here } //FUNCTION: adds two values __declspec(dllexport) float addition(float val_1, float val_2){ return val_1 + val_2; } //FUNCTION: substracts two values __declspec(dllexport) float substraction(float val_1, float val_2){ return val_1 - val_2; } //FUNCTION: multiplies two values __declspec(dllexport) float multiplication(float val_1, float val_2){ return val_1 * val_2; } //FUNCTION: divide two values __declspec(dllexport) float 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; } } </code></pre> <p>In Unity-3D here is the class:</p> <pre><code>using UnityEngine; using System.Collections; using System; using System.Runtime.InteropServices; public class PluginImport : MonoBehaviour { //Lets make our calls from the Plugin [DllImport("MathAssistant", EntryPoint = "?addition@ma@@YAMMM@Z")] private static extern float addition(float val_1, float val_2); [DllImport("MathAssistant", EntryPoint = "?substraction@ma@@YAMMM@Z")] private static extern float substraction(float val_1, float val_2); [DllImport("MathAssistant", EntryPoint = "?multiplication@ma@@YAMMM@Z")] private static extern float multiplication(float val_1, float val_2); [DllImport("MathAssistant", EntryPoint = "?division@ma@@YAMMM@Z")] 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)); } } </code></pre> <p>The error I was getting before was that the code was not recognizing my functions, addition, divide, etc. Even though I was declaring them correctly. However, when I created my .dll it somehow changed the name of my function, i.e: "addition" became: "?addition@ma@@YAMMM@Z". I went to this website and it made it clear: <a href="http://msdn.microsoft.com/en-us/library/system.entrypointnotfoundexception(v=vs.110).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.entrypointnotfoundexception(v=vs.110).aspx</a> and that is where I realized that the problem was not in my structure or the logic but in the actual function name once it was converted into .dll. If that is your case then what you need is a tool to help you find what your function name is. I used DependancyWalker.exe. Here is the is the site: <a href="http://dependency-walker.en.softonic.com/" rel="nofollow">http://dependency-walker.en.softonic.com/</a> That was my litle adventure trying to solve this issue. Hopefully this will help out anyone who has run into thi sisuue and has not resolved it yet. Power to the user!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload