[REBOL] Re: External library interface
From: ptretter:charter at: 2-Jul-2003 13:54
Not sure exactly what you going about doing but I use /Pro and do library
calls to winapi alot.
I usually define a string I want to pass to the library as:
Now if I receive a string from a library function to a pointer - in this
case we will call the pointer 'outstring
so what I would do on 'outstring is the following:
trim/with outstring "@"
Not sure if I helped you or not.
----- Original Message -----
From: "Ladislav Mecir" <[lmecir--mbox--vol--cz]>
Sent: Wednesday, July 02, 2003 8:12 AM
Subject: [REBOL] External library interface
I tried to help Cyphre with a specific problem (OpenGL 3D). I found a
following problem in the interface between Rebol strings and external
First I try to make a C string usable for an external function:
c_string: third make struct! [s [string!]] reduce [rebol_string]
So far so good, I created a binary! data (in fact a pointer), that can be
passed to a library function as a C string.
Now let's suppose, that a library function returns a C string. How can this
be done? One possibility is to store such a pointer into a Rebol integer.
Not having Rebol/Command, I cannot call a library function now, but I can
this situation using the C string I prepared above. To do it, I
just convert the above C string to a Rebol integer.
integer_struct: make struct! [i [integer!]] none
change third integer_struct c_string
Now I obtained the C string as an integer and I can pretend, that it is a
result of an external library function. What to do with it to obtain a Rebol
string? Let's try to use a similar "trick" as above:
result_integer_struct: make struct! [i [integer!]] reduce
result_string_struct: make struct! [s [string!]] none
change third result_string_struct third result_integer_struct
result_string: result_string_struct/s ; == "12"
Now the problem: as we have seen, the RESULT_STRING_STRUCT doesn't know the
length of the string (as usual for C strings) and therefore it assumes, that
the string is a null-terminated string as usual in C, so it "leaves off" a
part of the string. While this is reasonable for strings, I doubt, it is
reasonable for binary data, like images.
Do you have any idea how to handle binary data or strings containing null