C
C#7mo ago
surf

MarshalDirectiveException: Cannot marshal 'return value': Invalid managed/unmanaged type combination

Basically trying to wrap a dll (wiiuse library) into my godot game with c# and whenever i call my wrapped function i get this error:
E 0:00:00:0903 System.IntPtr[] WiiUse.WiiuseInit(int): System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'return value': Invalid managed/unmanaged type combination.
<C++ Error> System.Runtime.InteropServices.MarshalDirectiveException
<C++ Source> :0 @ System.IntPtr[] WiiUse.WiiuseInit(int)
<Stack Trace> :0 @ System.IntPtr[] WiiUse.WiiuseInit(int)
Test.cs:12 @ void Test._Ready()
Node.cs:2137 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
Test_ScriptMethods.generated.cs:48 @ bool Test.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)
E 0:00:00:0903 System.IntPtr[] WiiUse.WiiuseInit(int): System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'return value': Invalid managed/unmanaged type combination.
<C++ Error> System.Runtime.InteropServices.MarshalDirectiveException
<C++ Source> :0 @ System.IntPtr[] WiiUse.WiiuseInit(int)
<Stack Trace> :0 @ System.IntPtr[] WiiUse.WiiuseInit(int)
Test.cs:12 @ void Test._Ready()
Node.cs:2137 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
Test_ScriptMethods.generated.cs:48 @ bool Test.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)
My Code:
[DllImport("wiiuse.dll", EntryPoint = "wiiuse_init", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr[] WiiuseInit(int numWiimotes);
[DllImport("wiiuse.dll", EntryPoint = "wiiuse_init", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr[] WiiuseInit(int numWiimotes);
1 Reply
surf
surfOP7mo ago
My unbuilt function in c. (wiiuse library)
/**
* @brief Initialize an array of wiimote structures.
*
* @param wiimotes Number of wiimote_t structures to create.
*
* @return An array of initialized wiimote_t structures.
*
* @see wiiuse_connect()
*
* The array returned by this function can be passed to various
* functions, including wiiuse_connect().
*/
/**
* @brief Initialize an array of wiimote structures.
*
* @param wiimotes Number of wiimote_t structures to create.
*
* @return An array of initialized wiimote_t structures.
*
* @see wiiuse_connect()
*
* The array returned by this function can be passed to various
* functions, including wiiuse_connect().
*/
struct wiimote_t **wiiuse_init(int wiimotes)
{
int i = 0;
struct wiimote_t **wm = NULL;

/*
* Please do not remove this banner.
* GPL asks that you please leave output credits intact.
* Thank you.
*
* This banner is only displayed once so that if you need
* to call this function again it won't be intrusive.
*
* 2018: Replaced wiiuse.net with sourceforge project, since
* wiiuse.net is now abandoned and "parked".
*/
if (!g_banner)
{
printf("wiiuse v" WIIUSE_VERSION " loaded.\n"
" De-facto official fork at http://github.com/wiiuse/wiiuse\n"
" Original By: Michael Laforest <thepara[at]gmail{dot}com> <https://sourceforge.net/projects/wiiuse/>\n");
g_banner = 1;
}

logtarget[0] = stderr;
logtarget[1] = stderr;
logtarget[2] = stderr;
logtarget[3] = stderr;

if (!wiimotes)
{
return NULL;
}

wm = (struct wiimote_t **)malloc(sizeof(struct wiimote_t *) * wiimotes);

for (i = 0; i < wiimotes; ++i)
{
wm[i] = (struct wiimote_t *)malloc(sizeof(struct wiimote_t));
memset(wm[i], 0, sizeof(struct wiimote_t));

wm[i]->unid = i + 1;
wiiuse_init_platform_fields(wm[i]);

wm[i]->state = WIIMOTE_INIT_STATES;
wm[i]->flags = WIIUSE_INIT_FLAGS;

wm[i]->event = WIIUSE_NONE;

wm[i]->exp.type = EXP_NONE;
wm[i]->expansion_state = 0;

wiiuse_set_aspect_ratio(wm[i], WIIUSE_ASPECT_4_3);
wiiuse_set_ir_position(wm[i], WIIUSE_IR_ABOVE);

wm[i]->orient_threshold = 0.5f;
wm[i]->accel_threshold = 5;

wm[i]->accel_calib.st_alpha = WIIUSE_DEFAULT_SMOOTH_ALPHA;

wm[i]->type = WIIUSE_WIIMOTE_REGULAR;
}

return wm;
}
struct wiimote_t **wiiuse_init(int wiimotes)
{
int i = 0;
struct wiimote_t **wm = NULL;

/*
* Please do not remove this banner.
* GPL asks that you please leave output credits intact.
* Thank you.
*
* This banner is only displayed once so that if you need
* to call this function again it won't be intrusive.
*
* 2018: Replaced wiiuse.net with sourceforge project, since
* wiiuse.net is now abandoned and "parked".
*/
if (!g_banner)
{
printf("wiiuse v" WIIUSE_VERSION " loaded.\n"
" De-facto official fork at http://github.com/wiiuse/wiiuse\n"
" Original By: Michael Laforest <thepara[at]gmail{dot}com> <https://sourceforge.net/projects/wiiuse/>\n");
g_banner = 1;
}

logtarget[0] = stderr;
logtarget[1] = stderr;
logtarget[2] = stderr;
logtarget[3] = stderr;

if (!wiimotes)
{
return NULL;
}

wm = (struct wiimote_t **)malloc(sizeof(struct wiimote_t *) * wiimotes);

for (i = 0; i < wiimotes; ++i)
{
wm[i] = (struct wiimote_t *)malloc(sizeof(struct wiimote_t));
memset(wm[i], 0, sizeof(struct wiimote_t));

wm[i]->unid = i + 1;
wiiuse_init_platform_fields(wm[i]);

wm[i]->state = WIIMOTE_INIT_STATES;
wm[i]->flags = WIIUSE_INIT_FLAGS;

wm[i]->event = WIIUSE_NONE;

wm[i]->exp.type = EXP_NONE;
wm[i]->expansion_state = 0;

wiiuse_set_aspect_ratio(wm[i], WIIUSE_ASPECT_4_3);
wiiuse_set_ir_position(wm[i], WIIUSE_IR_ABOVE);

wm[i]->orient_threshold = 0.5f;
wm[i]->accel_threshold = 5;

wm[i]->accel_calib.st_alpha = WIIUSE_DEFAULT_SMOOTH_ALPHA;

wm[i]->type = WIIUSE_WIIMOTE_REGULAR;
}

return wm;
}
Want results from more Discord servers?
Add your server