x


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.

more ▼

asked Dec 02 '11 at 05:04 PM

RKS324 gravatar image

RKS324
16 4 4 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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).

more ▼

answered Dec 03 '11 at 12:28 AM

aldonaletto gravatar image

aldonaletto
41.4k 16 42 197

Can I use Standard MFC API function such as LoadLibrary?

Dec 03 '11 at 12:58 AM RKS324

I had some experience using specific plugins that I wrote in Delphi's Pascal, but honestly know nothing about MFC 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

Dec 03 '11 at 10:40 AM aldonaletto
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5069
x840
x392
x231

asked: Dec 02 '11 at 05:04 PM

Seen: 911 times

Last Updated: Dec 03 '11 at 10:40 AM