C ++ / CLI wrapper for native C / C ++ code, unable to load into Unity3D

I watched and looked on the net about how to load the assembly into Unity3D, and I have a very hard time. I apologize if this post will be long, but I will post everything that I learned and how far I got, since this is my first experience in .net and dll.

I have a native dll, it has a whole bunch of extern "C", so I can load everything at runtime. This works in unity if I use the [DLLImport] attribute, etc. However, this is cumbersome and not very reusable code. This will become even more cumbersome later when I have to abstract my system between more than one native library.

So, I decided that I would make a C +++ / CLI wrapper, and then load it into Unity3d, like any other DLL, and just contact the namespace: "using MyWrapper;"

I created the simplest C ++ / CLI lib that I could think of. all my libs have a class (Class1) and have an int getnum () {return 5;} function. I use VC ++ 2010 express, and I create a V90 and modified the vcxproj file for the target version 2.0. I know that unity only supports 2.0. I am creating in / clr to have my own and .net code.

It completely destroys unity3d. This is my error log in GameManager.Awake () [0x0001d] in the Manager \ GameManager.cs: 116 in GameManager.Awake () [0x00000] in the Manager \ GameManager.cs: 107 at (runtime-invoke shell) GUIRadioButton.runtime_invoke_void (object , intptr, intptr, intptr) <0xffffffff> Getting an unhandled NULL exception

/clr: safe, . /clr: pure .

, #, . lib, 2.0 /clr ( ) .

Unity 2.6 Pro.

, , , , .. , , , .NET. , (++).

.

++/cli.

#pragma once

using namespace System;

namespace CLRTest {

    public ref class Class1
    {
        // TODO: Add your methods for this class here.
    public:

        Class1(){}

        int getnum (){return 5;}
    };
}

#, . .

using System;
using System.Collections.Generic;
using System.Text;
using CLRTest;

namespace CLRTestLoad
{
    class Program
    {
        static void Main(string[] args)
        {
            Class1 c = new Class1();

            Console.WriteLine ("num is = " + c.getnum());
        }
    }
}

Unity3d . (, using)

Class1 c = new Class1();
+3
1

AFAIK, ++/CLI Unity, Unity Mono, . dll p/invoke

+4

All Articles