Not sure exactly what to name my question but,
I have some C# code that accesses a C dll using DllImports. In the C# code I have functions that are registered with and called by the C dll. The C dll calls the functions passing a pointer to them.
I have it working using an IntPtr to represent the arg in the C# callbacks.
working callback method:
public static int test(IntPtr lua_State)
Now the question:
I would like the argument type to instead be a class with 1 IntPtr field, and instance methods that would operate on that IntPtr
so the new callback method would look like:
public static int test(Lua lua_State)
and the class would be:
[StructLayout(LayoutKind.Sequential)]
public class Lua
{
IntPtr lua_State;
//Some random methods...
}
Unfortunately this is not working, the callback is getting called, but the Classes IntPtr field is not getting the value passed and is instead 0.
Is there a way to get this to work?
edit:
Deriving from SafeHandle works, however I would prefer to do it without the safehandle class as I don't want/need any excess it adds, all I need is the pointer value to be put into the IntPtr field of my class.
Lua.lua_Stateas an IntPtr ?