i have a type... its a well known type:
that is the structure of the first 14 bytes in a BMP file.Code:Public Type BITMAPFILEHEADER bfType As Integer bfSize As Long bfReserved1 As Integer bfReserved2 As Integer bfOffBits As Long End Type
What im doing is loading the first 14 bytes of a BMP into a byte array, then using LSet to set the 14 bytes to this
type. Like so:
Now this doent give me any errors at all... works great... but the values are not right after LSet has been called. I have used LSet alot, and it always works great.. was just using it for the type BITMAPINFOHEADER... no problems... i think it might have to do with the first section in the type being an integer... but i doubt it... but anyway, so i wrote my own LSet function using memory (if you understand the 3 basic memory calls, you should be able to understand this)Code:'This is a general decloration: Public Type MY_BYTE_STORAGE IN_ARDS_B(256) As Byte End Type 'store the first 14 bytes to a byte array: For i = 0 To 13 BYTE_STORE.IN_ARDS_B(i) = AscB(Mid(BufferA, i + 1, 1)) Next i 'use LSet to move it to the type LSet BM_FILE_HEADER = BYTE_STORE
This gives me exactly the same results...Code:Dim myPtr As Long, savePtr As Long Dim myStruc As BITMAPFILEHEADER 'allocate 14 bytes: myPtr = LocalAlloc(LPTR, 14) 'save the initial pointer value: savePtr = myPtr 'store the first 14 bytes of the buffer into the allocated: For i = 0 To 13 BYTE_STORE.IN_ARDS_B(i) = AscB(Mid(BufferA, i + 1, 1)) CopyMemory ByVal myPtr, ByVal VarPtr(BYTE_STORE.IN_ARDS_B(i)), 1 myPtr = myPtr + 1 Next i 'memcopy the 14 bytes at the original pointer to the pointer to my type CopyMemory ByVal VarPtr(myStruc), ByVal savePtr, 14 'free the memory used: LocalFree savePtr
can anyone tell me the most efficient way to take data and store it to a type?
thanks in advance,
Mouse




Reply With Quote