I try to use UnmanagedExports in my Unity project since I have one function which I would like to call from a Python program. I get the following error when I try to call the function in my Python script:
AttributeError: function 'ConvertRawToBinData' not found
Like mentioned here, I tried to build the project via x64 target. When I change the target to x64 in Visual Studio I cannot import my libraries:
The type or namespace name 'type/namespace' could not be found
Can I use UnmanagedExports in a Unity project and if yes, how?
Here is the C# code:
using RGiesecke.DllExport;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ConverterAPI
{
public class ConverterAPI
{
[DllExport("ConvertRawToBinData", CallingConvention = CallingConvention.StdCall)]
public static void ConvertRawToBinData(string settingsPath, string collectionSettingsPath, string rawDataPath)
{
Settings settings = Util.ImportJson<Settings>(settingsPath);
CollectionSettings CollectionSettings = Util.ImportJson<CollectionSettings>(collectionSettingsPath);
Converter.Convert(settings, CollectionSettings, rawDataPath);
}
}
}
Here is the Python code:
import ctypes
import os
from pathlib import Path, PurePath
apiPath = PurePath(assetsPath.parent, 'Build', 'Target', 'API.dll')
converterAPI = ctypes.cdll.LoadLibrary(str(apiPath))
converterAPI.ConvertRawToBinData("", "", "")