Passing a buffer to a foreign handler

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
DarScott
Posts: 227
Joined: Fri Jul 28, 2006 12:23 am
Location: Albuquerque
Contact:

Passing a buffer to a foreign handler

Post by DarScott » Tue Apr 19, 2016 2:46 am

This is part of the general problem of passing memory for sending or receiving arrays or structures to or from arbitrary functions in dynamic libraries created by others.

I want to create some memory and pass a pointer to it to a foreign handler.

One possibility is to create a value of type data and somehow pass the pointer to the raw bytes of that. That brings up some questions. (I know things might change.)

Can data move? That is, can I assume the pointer will still point to the first byte if I obey some rules like don't change the size? :?:

Is the data all contiguous? :?:

Is data automatically translated to pointer (to the first byte) when passed to foreign handler with a pointer or optional pointer parameter? :?: Or do I need to call a builtin function to get that? :?: Which one? :?:

The dynamic library will put bytes into the buffer until done and I can ask when it is done, or until I make it stop. I need to make sure the buffer size matches what I told the library.

Any recommendations on the right way to create a large chunk of data? :?:

(Another possibility is to use a memory allocation function and somehow get bytes out of it. Maybe that is the better way.)

DarScott
Posts: 227
Joined: Fri Jul 28, 2006 12:23 am
Location: Albuquerque
Contact:

Re: Passing a buffer to a foreign handler

Post by DarScott » Tue Apr 19, 2016 9:14 am

Ah, Peter TB Brett helped me out when I asked on the Use LiveCode list and somehow I didn't see the email. Yeah, one way to do this is to use Data and MCDataGetBytePtr().

Post Reply

Return to “LiveCode Builder”