PlanetSquires Forums

Support Forums => José Roca Software => Topic started by: Richard Kelly on May 22, 2026, 03:16:44 AM

Title: DWSTRING
Post by: Richard Kelly on May 22, 2026, 03:16:44 AM
I have a normal FB STRING that has been loaded with the contents of a JPEG file. When I set a DWSTRING = FB STRING the resulting DWSTRING is only 4 bytes long. Some code below. I have verified that sFileContents does have the contents of the JPEG file.

DIM sImageStream       AS DWSTRING
DIM sFileContents      AS STRING

' Get File Size

    uImageAttributes.ImageSize = oCFileSys.GetFileSize(szImageFile)

' Get Raw Stream

   sFileContents = STRING(uImageAttributes.ImageSize, 0)
   hFile = CreateFileW(@szImageFile, GENERIC_READ, FILE_SHARE_READ, NULL, _
                       OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL)
   ReadFile(hFile, STRPTR(sFileContents), uImageAttributes.ImageSize, @dwBytesRead, NULL)
   CloseHandle(hFile)

' Save Image for reference

    sImageStream = sFileContents
Title: Re: DWSTRING
Post by: José Roca on May 22, 2026, 09:23:37 AM
Never use DWSTRING or any other null-terminated string (WSTRING, ZSTRING) to store binary data. For that, use STRING or a buffer of bytes.

It does not make any sense to convert the contents of a JPEG file to Unicode.