dart ffi: dealing with Pointer<Void> parameter

679 views
Skip to first unread message

Maarten Boekhold

unread,
Nov 29, 2021, 3:03:26 AM11/29/21
to Dart Misc
Following up on my previous post (which I resolved), I'm stuck on another native function in this library for which I cannot figure out how to do the binding:

typedef Handle void;
Handle handle
int res = getHandle("myDevice", &handle);

My dart code looks like:

typedef Handle = Void;
typedef getHandle_native_t = Int32 Function(Pointer<Utf8> name, Pointer<Void> handle);
late int Function(Pointer<Utf8> name, Pointer<Void> handle) getHandle;
getHandle = library
    .lookup<NativeFunction<getHandle_native_t>>('getHandle')
    .asFunction();

// Here I'm stuck, how do I get an initialized "handle'?
Pointer<Handle> handlePointer = calloc(); // this compiles
String name = "myDevice";
int res = getHandle(name.toNativeUtf8(), handlePointer);
Handle handle = handlePointer.value; // compile error, no such property 'value'. "ref" doesn't exist either as a property...

How do I get to the "void" value? I need this value to pass to subsequent function calls...

Maarten

Daco Harkes

unread,
Nov 29, 2021, 5:13:18 AM11/29/21
to mi...@dartlang.org
Dear Maarten,

One can't dereference a void* in C, nor can one get the value of a Pointer<Void> in Dart.

What are you trying to accomplish? Do you have a link to your code somewhere? Is it an existing C API or one you are writing?

Kind regards,

 •  Daco Harkes
 •  Software Engineer
 •  dacoh...@google.com 
 •  🔵 Blue Dot Ally


--
For more ways to connect visit https://dart.dev/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/67264349-cfc5-4f23-94bc-6eb2d6d28ac4n%40dartlang.org.

Maarten Boekhold

unread,
Nov 30, 2021, 1:20:34 AM11/30/21
to Dart Misc, dacoh...@google.com
Hi Daco, your response prompted me to compose a very detailed description of what I'm (trying) to do, which had me jump into the source code of the library I'm trying to create bindings for. This proved very useful as it led me to discover my mistake: I need to deal with a **void, not *void. So in Dart, "Pointer<Pointer<Void>> handle = calloc();". I have much progressed now. Thanks for responding to my query,

Maarten
Reply all
Reply to author
Forward
0 new messages