-
i have a type... its a well known type:
Code:
Public Type BITMAPFILEHEADER
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
that is the structure of the first 14 bytes in a BMP file.
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:
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
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:
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
This gives me exactly the same results...
can anyone tell me the most efficient way to take data and store it to a type?
thanks in advance,
Mouse
-
Why don't you load it directly from the file.
Code:
Dim header as BITMAPFILEHEADER
Open "C:\bitmaps\bitmap.bmp" for binary as #1
Get#1,,Header
Close #1
-
wow
well, ill be damned
all that fricken work and it turns out to be something
so simple...
haha thanks man, you saved me 1000 headaches
-
oh wait...
what if it isnt in file form... what if the BMP is stored
to a varible... cause what im doing is getting the BMP data from a service on the web...
i could just save it to disk, but that is sloppy and a waist of time...
is there anyway to do the same technique but with a string?
-
Hehe, You really tried to make it the hard way :)
Hmm, if you want to DL, i'm not sure what you should do, you could try download the first14 bytes put it in a file and then read them