H
H
HellFingers2019-12-14 15:00:57
C++ / C#
HellFingers, 2019-12-14 15:00:57

C++ DLL not connecting to Unity?

Good evening, there is a working x86 dll. For the project, it is necessary to import it into Unity and call the function from the dll when the button is pressed. The code:

using System.Runtime.InteropServices;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using System.Runtime.InteropServices;
public class ButtonPressed : MonoBehaviour
{
    public InputField testField;
    public Dropdown testDrop;
    public Toggle testToggle;
    [DllImport("C:\\Users\\path_to_Assets\\Assets\\Plugins\\DLL2.dll", EntryPoint = "[email protected]@[email protected]")]
    public static extern int Summ(int first, int second);
    public void Press()
    {
        Debug.Log(Summ(5, 2));
    }
}

dll is placed in the Plugins folder. After clicking on the button, it throws a DllNotFoundException error. Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
5
50Dreams, 2019-12-27
@50Dreams

First, if the library is compiled for 64-bit architecture, then it must be located in the "x64" folder (Assets -> Plugins -> x64 -> mylib.dll).
Second, don't specify the full path! When you make a build the game will not be able to find your dlls!!! In DllImportjust specify the name of your library without extension (i.e. without ".dll").
Third, look for an indication that the function is being exported from a DLL.
Fourth, as it was said , freeExec can be used before defining a function, then you can pass the name of the function to ;) Fifth, check your library import settings and check the necessary boxes in Include Platforms: I hope I explained everything clearly, good luck to you;) extern "C"DllImport -> EntryPoint

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question