The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: James Ladd on May 08, 2005, 08:07:07 AM

Title: Defining a structure with a byte array in it ?
Post by: James Ladd on May 08, 2005, 08:07:07 AM
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
Title: Re: Defining a structure with a byte array in it ?
Post by: thomasantony on May 08, 2005, 08:38:20 AM
Yes :U
Title: Re: Defining a structure with a byte array in it ?
Post by: Mark Jones on May 08, 2005, 02:57:48 PM
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.
Title: Re: Defining a structure with a byte array in it ?
Post by: James Ladd on May 08, 2005, 09:13:57 PM
Mark,
Thanks, but I wanted the memory fixed and not dynamic.
Ill keep you approach in mind though.
Thanks Thomas.

Rgs, striker
Title: Re: Defining a structure with a byte array in it ?
Post by: Mark Jones on May 08, 2005, 10:46:49 PM
James, I think LPTR signifies LMEM_FIXED + LMEM_ZEROINIT, and nBytes can be a literal value, variable, or constant. Hope that helps. :)