Further to my question, I discover that my problem is more complex to solve, as I could potentially encounter the situation described below.
Strings are encoded in Windows Unicode-BMP format, which consists in encoding the character value on 2 bytes (a WORD). To retrieve the string from memory or a file, each character must be concatenated with Chr().
Except that in memory or in the file, for example, an 'A' is encoded $00 41 and not $41 00. As a result, I can't use PEEK with the #PB_Unicode option.
In short, is it possible to retrieve in one shot a string coded $00 41 instead of $41 00, or $03 9A instead of $9A 03, (without having to use a loop for each character)?
I've also tried WideCharToMultiByte but didn't succeed (maybe I didn't use the right parameters).
To better understand the situation, here's an example (valid only with intel memory alignment). Click on Start after each CallDebugger
Code: Select all
Procedure.s MemoryRead(*ArgBuffer,ArgLength.a)
Protected.a Count
Protected.u Value
Protected.s String
ArgLength-2
For Count=0 To ArgLength Step 2
Value=PeekW(*ArgBuffer+Count)
Value=(Value&$FF)<<8+(Value>>8)&$FF
String+Chr(Value)
Next
ProcedureReturn String
EndProcedure
String.s="Normal"
Debug "Memory bloc is equal to (with Intel alignment) : 4E 00 6F 00 72 00 6D 00 61 00 6C 00"
Debug "Reading memory (#PB_Unicode) : "+PeekS(@string,12,#PB_Unicode)
ShowMemoryViewer(@String,Len(String)*2)
CallDebugger
*Buffer=AllocateMemory(13)
CopyMemory(@String,*Buffer+1,12)
Debug "Memory bloc is equal to (with Intel alignment) : 00 4E 00 6F 00 72 00 6D 00 61 00 6C"
Debug "Reading memory (MemoryRead procedure) : "+MemoryRead(*Buffer,12)
Debug "Reading memory (#PB_Ascii) : "+PeekS(*Buffer,12,#PB_Ascii)
Debug "Reading memory (#PB_UTF8) : "+PeekS(*Buffer,12,#PB_UTF8)
Debug "Reading memory (#PB_Unicode) : "+PeekS(*Buffer,12,#PB_Unicode)
String2.s=Space(6)
*buffer2=AllocateMemory(6)
WideCharToMultiByte_(#CP_ACP,0,@String,12,*buffer2,6,0,0)
Debug "WideCharToMultiByte : "+PeekS(*buffer2,6,#PB_Ascii)
; String2.s=Space(20)
; Longueur=WideCharToMultiByte_(#CP_ACP,0,@String,12,@String2,6,0,0)
; Debug "String2 : "+String2
; ShowMemoryViewer(@String2,6)
;CallDebugger
Debug "----"
String="Κανονικά"
ReAllocateMemory(*Buffer,17)
CopyMemory(@String,*Buffer+1,16)
PokeB(*Buffer,3)
Debug "Memory bloc is now equal to (with Intel alignment) : 03 9A 03 B1 $03 BD 03 BF 03 BD 03 B9 03 BA 03 AC"
Debug "Reading memory (MemoryRead procedure) : "+MemoryRead(*Buffer,16)
Debug "Reading memory (#PB_Ascii) : "+PeekS(*Buffer,16,#PB_Ascii)
Debug "Reading memory (#PB_UTF8) : "+PeekS(*Buffer,16,#PB_UTF8)
Debug "Reading memory (#PB_Unicode) : "+PeekS(*Buffer,16,#PB_Unicode)
String2=Space(16)
ReAllocateMemory(*buffer2,16)
WideCharToMultiByte_(#CP_ACP,0,@String,16,@String2,8,0,0)
Debug "WideCharToMultiByte : "+String2
WideCharToMultiByte_(#CP_ACP,0,@String,16,*buffer2,8,0,0)
ShowMemoryViewer(*Buffer2,16)
CallDebugger