Results 1 to 5 of 5

Thread: Question with LSet... advanced VBers reply only...

  1. #1

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    Question

    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

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    Cool 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

  4. #4

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    Exclamation

    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?

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width