News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Defining a structure with a byte array in it ?

Started by James Ladd, May 08, 2005, 08:07:07 AM

Previous topic - Next topic

James Ladd

I need a structure that contains a buffer and I have defined it as follows

    MYSTRUCT struct
        buffer BYTE[4096] ?
    MYSTRUCT ends


Is this what I expect as it compiles ok.
ie: I have a buffer of 4096 bytes

thomasantony

There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Mark Jones

Striker, I can think of something else you could try. I'm no pro at this and this code is untested:


.data
    MYSTRUCT struct
        lpBuffer DWORD 0  ; lpBuffer is a pointer
    MYSTRUCT ends

.code
    invoke LocalAlloc, LPTR, nBytes ; locked buffer of nBytes
; If the function fails, the return value is NULL.
; To get extended error information, call GetLastError.
    mov MYSTRUCT.lpBuffer, eax  ; save our pointer

; When the buffer is no longer needed, it must be freed!
    invoke LocalFree, MYSTRUCT.lpBuffer


GlobalAlloc GPTR will also work, but they all access the same flat memory in Win32.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

James Ladd

Mark,
Thanks, but I wanted the memory fixed and not dynamic.
Ill keep you approach in mind though.
Thanks Thomas.

Rgs, striker

Mark Jones

James, I think LPTR signifies LMEM_FIXED + LMEM_ZEROINIT, and nBytes can be a literal value, variable, or constant. Hope that helps. :)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08