You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m encountering an issue where I cannot properly generate a delegate in C# for a Rust function pointer type defined as pub type BatteryLevelCallback = extern "C" fn(id: *const c_char, battery_level: u8). The Rust code exposes this type and a corresponding function, but the C# interop seems to fail when defining the delegate.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]internaldelegateintcallback_test_cb_delegate(inta);[DllImport(__DllName,EntryPoint="callback_test",CallingConvention=CallingConvention.Cdecl,ExactSpelling=true)]internalstaticexternintcallback_test(callback_test_cb_delegatecb);// Attempted delegate for BatteryLevelCallback - this is where the issue arises[DllImport(__DllName,EntryPoint="set_battery_level_callback",CallingConvention=CallingConvention.Cdecl,ExactSpelling=true)]internalstaticexternvoidset_battery_level_callback(set_battery_level_callback_callback_delegatecallback);
Problem
The callback_test function works as expected with its delegate callback_test_cb_delegate.
However, defining a delegate for set_battery_level_callback (e.g., set_battery_level_callback_callback_delegate) fails. The C# compiler or runtime does not recognize or properly bind to the BatteryLevelCallback type
Expected Behavior
I expect to define a delegate in C# that matches the BatteryLevelCallback type, allowing me to pass a callback function from C# to Rust via set_battery_level_callback.
Additional Notes
The callback_test example with a simple i32 parameter and return type works fine, suggesting the issue is specific to the BatteryLevelCallback signature.
Is there a correct way to define the delegate for extern "C" fn(id: *const c_char, battery_level: u8) in C#?
The text was updated successfully, but these errors were encountered:
I’m encountering an issue where I cannot properly generate a delegate in C# for a Rust function pointer type defined as pub type BatteryLevelCallback = extern "C" fn(id: *const c_char, battery_level: u8). The Rust code exposes this type and a corresponding function, but the C# interop seems to fail when defining the delegate.
Problem
The
callback_test
function works as expected with its delegatecallback_test_cb_delegate
.However, defining a delegate for
set_battery_level_callback
(e.g.,set_battery_level_callback_callback_delegate
) fails. The C# compiler or runtime does not recognize or properly bind to theBatteryLevelCallback
typeExpected Behavior
I expect to define a delegate in C# that matches the
BatteryLevelCallback
type, allowing me to pass a callback function from C# to Rust viaset_battery_level_callback
.Additional Notes
The callback_test example with a simple i32 parameter and return type works fine, suggesting the issue is specific to the BatteryLevelCallback signature.
Is there a correct way to define the delegate for
extern "C" fn(id: *const c_char, battery_level: u8)
in C#?The text was updated successfully, but these errors were encountered: