Hello,
Should a memoryblock of WString have the same binary length as a variable WString?
A WString is a null terminated, 2 bytes-per-character value.
On Windows, when I create a WString variable, here is the Binary that has a length of 8 bytes:
Dim c as WString = "Time"
Binary: 5400 6900 6D00 6500
When I attempt to create this type with bytes in a memory block, I need to add 2 bytes to terminate the WString to work, for a total of 10 bytes:
m.Byte(0) = &h54 // ASCII 'T'
m.Byte(1) = &h00
m.Byte(2) = &h69 //ASCII 'i'
m.Byte(3) = &h00
m.Byte(4) = &h6D //ASCII 'm'
m.Byte(5) = &h00
m.Byte(6) = &h65 //ASCII 'e'
m.Byte(7) = &h00
m.Byte(8) = &h00 //null termination
m.Byte(9) = &h00
Binary: 5400 6900 6D00 6500 0000
To show WString by MemoryBlock or by variable, shouldn’t the WString length be the same? Or is there a case where WString is not the same as Wstring? Just curious to know what I am missing. Thanks!
Here is the complete code:
[code]Sub Action() Handles Action
//x86 and x64 compatible
//Show a null terminated Wstring
//Create a new MemoryBlock of 8 or 10 bytes?
Dim c as WString = “Time”
Dim m as new MemoryBlock(10)
//Add data in byte location #0
m.Byte(0) = &h54 // ASCII ‘T’
m.Byte(1) = &h00
m.Byte(2) = &h69 //ASCII ‘i’
m.Byte(3) = &h00
m.Byte(4) = &h6D //ASCII ‘m’
m.Byte(5) = &h00
m.Byte(6) = &h65 //ASCII ‘e’
m.Byte(7) = &h00
m.Byte(8) = &h00 //null termination
m.Byte(9) = &h00
//Show data in location #0
LblData.text = "The value of WString is: " + m.WString(0)
LblData1.text = "The value of WString is: " + c
break
End Sub[/code]