- Home /
Mfc dll file can use as unity plugin?
I have an MFC dll file and source project. I wonder can i use it as an unity plugin file? Then how can I use it? Need help.
Answer by aldonaletto · Dec 03, 2011 at 12:28 AM
In principle, you can use any DLL file as a plugin in Unity - this is a .NET feature, and is accessible via C# scripts.
You must write a C# script to import the functions, like this one:
using UnityEngine; using System.Collections; using System.Runtime.InteropServices;
public class MyDll : MonoBehaviour {
[DllImport("MyDllFile")]
public static extern int Function1(int v1);
[DllImport("MyDllFile")]
public static extern float Function2(float v2);
} This script imports the functions Function1 and Function2 from the DLL file "MyDllFile.dll" stored in the Plugins folder.
Since the functions are defined as static in the MyDll script, you can use them in other scripts as MyDll.Function1(), MyDll.Function2() etc.
NOTE: Unfortunately, JS and CS scripts don't see each other at compile time, thus JS users (like me) will have some trouble to use imported functions: it's necessary to save the script above in the Plugins folder, and the JS scripts in some other folder compiled after Plugins (see Script Compilation to learn more about this).
Can I use Standard $$anonymous$$FC API function such as LoadLibrary?
I had some experience using specific plugins that I wrote in Delphi's Pascal, but honestly know nothing about $$anonymous$$FC functions. If LoadLibrary will link to a second DLL, you may have problems - see this question: http://answers.unity3d.com/questions/187694/dllnotfound-when-the-plugin-c-dll-links-another-c.html
Your answer
Follow this Question
Related Questions
Distributing Precompiled Scripts 1 Answer
Sending and receiving variable-length arrays to and from DLL 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Can I use my own input device? 4 Answers
reference my .dll plugin 0 Answers