Reputation: 13
I am trying to use my C++ dll on Unity, so I copied it in Assets/Plugins and at the root of the project but I have DllFoundException when I use the Play button or run the .exe file generated by the build. It doesn't even work when I use the absolute path of the dll file in the DllImport.
However, it works fine when I Build&Run the project.
Unity Code
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using Dummiesman;
public class morph_face : MonoBehaviour
{
bool morphed;
[DllImport(@"facemorph", CallingConvention=CallingConvention.Cdecl)]
static extern void morphModelsPoints(string src_model, string src_csv,
string dst_csv, string output_path);
public GameObject model;
// Start is called before the first frame update
void Start()
{
morphed = false;
}
// Update is called once per frame
void Update()
{
if (!morphed && Input.GetKeyDown("space")) {
Debug.Log("SpaceBar pressed the model will be modified.");
morphModelsPoints("Data/src.obj", "Data/src.csv", "Data/dst.csv",
"Data/res.obj");
//disable old mesh
model.SetActive(false);
OBJLoader obj = new OBJLoader();
model = obj.Load("Data/res.obj");
//displays new mesh
model.SetActive(true);
morphed = true;
}
}
}
The Dll was built with this configuration: Release/Win32.
Here's the dll import settings :
Upvotes: 1
Views: 2094
Reputation: 3693
※Please correct me if I am wrong
If I am not mistaken, you can not use 32 dlls in Editor because UNITY is 64bit. If you can just rebuild your dll to 64bit. If you build a standalone then you must set your architecture to x86 instead of x86_64 in Build Settings.
Upvotes: 1