Quick help with my DLL exception, please.

Yeah yeah another one of these “DllNotFoundException” questions, First I just need some help compiling my scene and I’ll be out of your hair.

I have personal licence for unity not professional so if that’s the reason I can’t link my dll you can stop and let me know.

If I can link dlls in unity 5.4 on a personal version please read below for the code:

I am building the DLL in visual studio 2015, in debug 64. Then dragging and dropping the dll in a plugins folder located inside another project directory.

I’m sorry, I have no idea why this image got so crazy…

Console.cpp

#include "Main.h"
extern "C" {
	const char* Test()
	{
		return "Why don't you fkn work!?!?";
	}
}

console.h

#pragma once
#define Main __declspec(dllexport) 

extern *"C" {
	char Test();
}

RunPlugin.cs

using UnityEngine;
using System.Runtime.InteropServices;
 
public class RunPlugin : MonoBehaviour
{
    // The imported function
    [DllImport("Console", EntryPoint = "Test")]
    public static extern void Test();

    void Start()
    {
        Test();
    }
}

Two things:

  • First of all your dll is named “Console.dll” not “Console”. So you’re missing the “.dll” in side the DllImport attribute.
  • Second your method “Test” is “returning” a char pointer but you’re extern definition in C# doesn’t return anything. You should return a string and actually do something with the returned value:

Like this:

 using UnityEngine;
 using System.Runtime.InteropServices;
  
 public class RunPlugin : MonoBehaviour
 {
     // The imported function
     [DllImport("Console.dll", EntryPoint = "Test")]
     public static extern string Test();
 
     void Start()
     {
         Debug.Log("The dll returned: " + Test() );
     }
 }

ps: Also keep in mind since you marked that plugin as “Standalone” only you can’t test this inside the editor. If you want to test inside the editor you have to enable “Editor” as well. If that plugin doesn’t work on the editor platform for some reason (when you’re using a different platform for development than for building), you would need a seperate implementation of the same thing for the editor if you want to test inside the editor.