I'm trying to Marshal this C++ test DLL with C interface which works when calling from Python using CFFI:
#define AS_TYPE(Type, Obj) reinterpret_cast<Type *>(Obj)
#define AS_CTYPE(Type, Obj) reinterpret_cast<const Type *>(Obj)
struct mytype_s;
typedef struct mytype_s mytype_t;
namespace TestDLL {
class Test {
public:
Test() { return; }
~Test() { return; }
int test_function() const { return 314159; }
};
}
mytype_t *test_new() {
return AS_TYPE(mytype_t, new TestDLL::Test());
}
int test_function(const mytype_t *mytype) {
return AS_CTYPE(TestDLL::Test, mytype)->test_function();
}
From C# I tried using an IntPtr for mytype_t which had worked for me with structures in the past. The C# code:
[DllImport(dllPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr test_new();
[DllImport(dllPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int test_function(IntPtr mytype);
IntPtr mytype;
mytype = test_new();
Console.WriteLine("Alloc complete");
int result;
result = test_function(mytype);
Console.WriteLine("test: {0}", result);
But I get the error:
Alloc complete
Unhandled Exception: System.EntryPointNotFoundException: Unable to find an entry point named 'test_function' in DLL
Is this related to how I marshalled the mytype_t or a more complex issue with passing the object from C++ to C#?
Thanks