Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to use a C++ dll in Unity3D

Discussion in 'Scripting' started by Axiang666, Sep 26, 2019.

  1. Axiang666

    Axiang666

    Joined:
    Jun 23, 2017
    Posts:
    6
    I want to use C++ DLL in Unity, but I am prompted with “DllNotFoundException” error in Unity.I tried the method of others on the network, it didn't work for me.



    I want to use C++ DLL in Unity, but I am prompted with “DllNotFoundException” error in Unity.I tried the method of others on the network, it didn't work for me.

    I tried the method on Unity's official website, but it didn'twork.
    https://docs.unity3d.com/2017.3/Documentation/Manual/NativePlugins.
    html
    https://docs.unity3d.com/2017.3/Documentation/Manual/PluginsForDesktop.html
    Running the SimplestPluginExample Demo of Unity's official website is also prompted with “DllNotFoundException” error in Unity.

    ```vs2013, .NET Framwork 3.5, MyDLL.cpp:
    extern "C" int __declspec(dllexport) AddTwoIntegers(int a, int b)
    {
    return a + b;
    }
    ```

    ```
    put the MyDLL.dll in Assets/Plugins
    ```

    ```Unity2017.3.0f3
    [DllImport("MyDLL")]
    private static extern int AddTwoIntegers(int a, int b);
    void Start ()
    {
    Debug.Log(AddTwoIntegers(2, 3));
    }
    ```

    ```Unity error tip
    DllNotFoundException: MyDLL
    ```
     
  2. Axiang666

    Axiang666

    Joined:
    Jun 23, 2017
    Posts:
    6
    I solved my problem.My system is 64 bit.I used VS to create 64-bit DLL.This dll in my Unity is correct,not error tip.