|
#1
|
|||
|
|||
|
String Variable Layout and copyMemory
hi everyone
im trying to read 2 numbers stored in string, but they are a string representation of a 16 bytes integer, they mean coordinates for example. i have this "¹K ¬K" from 0 to 2 is the X coordinate, and from 4 to 6 is the Y coordinate. if these bytes were in a byte array would be simple to get the integer number, just copyng from pos 0 to 2 to the memory of a integer variable, would give me the x coordinate and 4 to 6 the y one. but in the string the data is stored as unicode and they have 4 bytes(reserved) at the beginning for storing its lenght so i would be using bytes from 4 and up. but how would be a easy way to get those numers from the strings? Thx in advance!!! |
|
#2
|
|||
|
|||
|
Okay, to convert from unicode to ansi use strconv function with the vbFromUnicode as the parameter...
Good Luck |
|
#3
|
|||
|
|||
|
would that change the layout of string variable on memory? i think it wont but thx for the answer, i alreasy solved that just using a loop to convert it hehe i was avoiding that cause is slow, but still ok, now i have a trouble cause isnt a integer as i tought is a mini float a 2 bytes floating point and cannot obtain the alue =(.
|
|
#4
|
|||
|
|||
|
No it should not change the value in memory as it is meant to read from one variable into another. Glad you have it solved...
Good Luck |
|
#5
|
|||
|
|||
|
here is the code to convert to float, if someone else needs it.
the same can be done to double, long, integer etc just change the varyable type of the dest on copymemory and of course the bytes selection lenght of copymemory. Code:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Sub ConvertBytesToSingle(DArr() As Byte, float As single) 'for Byte arrays with 1 as minimun index CopyMemory float, 1, 4 End Sub |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|