Quantcast
Channel: Questions in topic: "native plugin"
Viewing all articles
Browse latest Browse all 376

Using C++ classes in native DLL for Unity

$
0
0
I'd like to use classes written in my C++ native plugin in Unity. Here's my attempt. The C++ code (compiles fine): // frontengine.cpp #include "stdafx.h" #include "FrontENGINE.h" extern "C++" { FRONTENGINE_API int Add(int a, int b) { return a + b + 10; } FRONTENGINE_API class TestClass { int var; public: void setvar(int a) { var = a; } int getvar() { return var; } }; } The Unity Code: // dosomething.cs using System.Runtime.InteropServices; public class DoStuff : MonoBehaviour { [DllImport("FRONT-Engine")] static extern int Add(int a, int b); void Start() { Debug.Log("Test"); TestClass nq = new TestClass(); nq.setvar(43); Debug.Log(nq.getvar()); } } What I get when I try this: error CS0246: The type or namespace name `TestClass' could not be found. Are you missing an assembly reference?

Viewing all articles
Browse latest Browse all 376

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>