Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[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: mystring: "test^@" 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. Paul ----- Original Message ----- From: "Ladislav Mecir" <[lmecir--mbox--vol--cz]> To: <[rebol-list--rebol--com]> Sent: Wednesday, July 02, 2003 8:12 AM Subject: [REBOL] External library interface Hi all, I tried to help Cyphre with a specific problem (OpenGL 3D). I found a following problem in the interface between Rebol strings and external strings. First I try to make a C string usable for an external function: rebol_string: "12^(0)4" 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 simulate 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 rebol_integer: integer_struct/i 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 [rebol_integer] 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 characters? -L