Raylib Wrapper Help
#12
I typically pass strings to external libraries as _OFFSET. This isn't something you necessarily have to do but I feel safer doing it. It kind of forces you to declare your string variable and then it makes you remember to also null-terminate it with a CHR$(0). Whether you do it as a BYVAL _OFFSET or just STRING, the result is the same, provided you still null-terminate. I only do it this way for consistency, since the reference code shows these strings as pointers to strings. Also, I have set the BI to use $CONSOLE:ONLY since you will have no need for a QB64 window in your binary. Also, Raylib outputs some handy-dandy information to the console for debugging. Will be quite helpful, I'm sure. I would offer more assistance with using the BI file and functions but, unfortunately, I'm not a graphics person so I'm not too familiar with this library. However, if you find some C code that you want to replicate using this library, I can probably get it to at least work a little bit. Maybe. No guarantees Smile

Also, regarding the strings being passed as _OFFSET.... Believe it or not, it makes it that much easier to deal with the strings with external libraries, especially when one has a mixture of UTF-8 and ANSI. Rather trivial to convert a pointer to a string in QB64 and I do it quite often. Below is some code I use but there are actually a few different ways to get the string content of an OFFSET
Code: (Select All)
$If PTRTOSTR = UNDEFINED Then
    $Let PTRTROSTR = DEFINED
    $If 64BIT Then
        Declare Library ".\internal\c\c_compiler\x86_64-w64-mingw32\include\strsafe"
        End Declare
    $Else
            Declare Library ".\internal\c\mingw32\i686-w64-mingw32\include\strsafe"
            End Declare

    $End If
    Function PointerToWideString$ (pointer As _Offset)
        $If WCSLEN = UNDEFINED Then
            $Let WCSLEN = DEFINED
            Declare CustomType Library
                Function wcslen%& (ByVal str As _Offset)
            End Declare
        $End If
        Declare CustomType Library
            Sub StringCchCopyW (ByVal pszDest As _Offset, Byval cchDest As _Offset, Byval pszSrc As _Offset)
        End Declare
        Dim As _Offset length: length = wcslen(pointer) * 2 'The length does not account for the 2-byte nature of Unicode so we multiply by 2
        Dim As String __dest: __dest = Space$(length)
        StringCchCopyW _Offset(__dest), Len(__dest), pointer
        PointerToWideString = __dest
    End Function

    Function PointerToString$ (pointer As _Offset)
        $If TCSLEN = UNDEFINED Then
            $Let TCSLEN = DEFINED
            $If 64BIT Then
                Declare CustomType Library ".\internal\c\c_compiler\x86_64-w64-mingw32\include\tchar"
                    Function tcslen%& Alias "_tcslen" (ByVal str As _Offset)
                End Declare
            $Else
                    Declare CustomType Library ".\internal\c\c_compiler\i686-w64-mingw32\include\tchar"
                    Function tcslen%& Alias "_tcslen" (ByVal str As _Offset)
                    End Declare
            $End If
        $End If
        Declare CustomType Library
            Sub StringCchCopyA (ByVal pszDest As _Offset, Byval cchDest As _Offset, Byval pszSrc As _Offset)
        End Declare
        Dim As _Offset length: length = tcslen(pointer) + 1
        Dim As String __dest: __dest = Space$(length)
        StringCchCopyA _Offset(__dest), Len(__dest), pointer
        PointerToString = __dest
    End Function
$End If

In the above code, PointerToWideString is used to convert an OFFSET which references a unicode string. PointerToString is used to convert an OFFSET which references an ANSI string.
Ask me about Windows API and maybe some Linux stuff
Reply


Messages In This Thread
Raylib Wrapper Help - by LeftyG - 08-27-2022, 07:44 PM
RE: Raylib Wrapper Help - by SMcNeill - 08-27-2022, 09:33 PM
RE: Raylib Wrapper Help - by LeftyG - 08-27-2022, 09:39 PM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-29-2022, 03:44 PM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-29-2022, 07:13 PM
RE: Raylib Wrapper Help - by LeftyG - 08-29-2022, 09:29 PM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-30-2022, 02:43 AM
RE: Raylib Wrapper Help - by LeftyG - 08-30-2022, 03:05 AM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-30-2022, 05:00 AM
RE: Raylib Wrapper Help - by LeftyG - 08-30-2022, 05:25 AM
RE: Raylib Wrapper Help - by TempodiBasic - 08-30-2022, 05:07 AM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-30-2022, 05:37 AM
RE: Raylib Wrapper Help - by LeftyG - 08-30-2022, 05:49 AM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-30-2022, 12:07 PM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-30-2022, 12:12 PM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-30-2022, 12:45 PM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-30-2022, 04:49 PM
RE: Raylib Wrapper Help - by LeftyG - 08-30-2022, 06:38 PM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-30-2022, 06:49 PM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-30-2022, 07:21 PM
RE: Raylib Wrapper Help - by SpriggsySpriggs - 08-30-2022, 07:43 PM
RE: Raylib Wrapper Help - by LeftyG - 08-30-2022, 08:55 PM



Users browsing this thread: 6 Guest(s)