Hi,
I created a DLL from a C++ project and wanted to use its functions in Unity, but I still have difficulties with callbacks. I keep on getting the error EntryPointNotFoundException: WacomMTRegisterAttachCallback.
Here the C++ file:
extern "C" {
#include <stdlib.h>
typedef enum _WacomMTError
{
WMTErrorSuccess = 0,
WMTErrorDriverNotFound = 1,
WMTErrorBadVersion = 2,
WMTErrorAPIOutdated = 3,
WMTErrorInvalidParam = 4,
WMTErrorQuit = 5,
WMTErrorBufferTooSmall = 6
} WacomMTError;
typedef void (__stdcall * WMT_ATTACH_CALLBACK)(WacomMTCapability deviceInfo, void *userData);
__declspec(dllexport) WacomMTError __stdcall WacomMTInitialize(int libraryAPIVersion);
__declspec(dllexport) WacomMTError __stdcall WacomMTRegisterAttachCallback(WMT_ATTACH_CALLBACK attachCallback, void *userData);
}
The C# file in Unity:
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System;
using UnityEngine;
enum WacomMTError
{
WMTErrorSuccess = 0,
WMTErrorDriverNotFound = 1,
WMTErrorBadVersion = 2,
WMTErrorAPIOutdated = 3,
WMTErrorInvalidParam = 4,
WMTErrorQuit = 5,
WMTErrorBufferTooSmall = 6
}
public class PluginTest : MonoBehaviour {
[DllImport("WacomFeel")]
private static extern WacomMTError WacomMTInitialize(int libraryAPIVersion);
private delegate void AttachCallbackDel(WacomMTCapability deviceInfo, IntPtr userData);
[DllImport("WacomFeel")]
private static extern WacomMTError WacomMTRegisterAttachCallback(AttachCallbackDel attachCallback, IntPtr userData);
private AttachCallbackDel attachCallbackDel;
private static void AttachCallback(WacomMTCapability deviceInfo, IntPtr userData)
{
//do something
}
void Start () {
WacomMTError test = WacomMTInitialize(4);
Debug.Log(test); //returns success
attachCallbackDel = new AttachCallbackDel(AttachCallback);
test = WacomMTRegisterAttachCallback(attachCallbackDel, IntPtr.Zero);
Debug.Log(test); //no return due to error
}
}
The function WacomMTInitialize works fine, but calling WacomMTRegisterAttachCallback brings an error. Any suggestions?