C-Library and STRING-Parameters - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: C-Library and STRING-Parameters (/showthread.php?tid=1972) |
C-Library and STRING-Parameters - BSpinoza - 09-07-2023 I want to use a C-Library together with QB64. This works fine with number types as parameters. But is this possible with strings (in C I have to use an array, I know!) and if yes, how ? In the Help or Wiki of QB64 there is written (chapter "DECLARE LIBRARY"): "Parameters used by the Library procedure must be passed by value (BYVAL) except for STRING characters." RE: C-Library and STRING-Parameters - DSMan195276 - 09-07-2023 To pass a string to a function in C you have it take a `char *` parameter. In concept this is similar to a by-ref pass in QB64, you're given a pointer to the string contents rather than a copy of the string contents. A `String` parameter in `Declare Library` is the same, a by-ref pass will pass the `String` as a `char *` to the C function. Note that C is expecting the string to be NUL terminated, QB64 string's are not so you'll have to add the NUL yourself. You're not allowed to pass a char array by-value to a C function, so as a consequence you can't pass a `String` by-value to a C function either. RE: C-Library and STRING-Parameters - RhoSigma - 09-07-2023 (09-07-2023, 10:42 AM)BSpinoza Wrote: I want to use a C-Library together with QB64. You can have a look into my RegEx example or the QB-StdLibs folder in my Libraries collection to analyze how to pass strings and how to get back a string from the C function. Simply follow the Library link in my signature. RE: C-Library and STRING-Parameters - BSpinoza - 09-08-2023 Many thanks for all your answers! This is what I want to know. |