The MASM Forum

General => The Campus => Topic started by: Nickmare on January 23, 2016, 06:09:44 AM

Title: Initializing STRUCT in visual studio doesn't work
Post by: Nickmare on January 23, 2016, 06:09:44 AM
I'm wondering how I can initialize a STRUCT when assembling in Visual Studio 2015 without getting an error.

The following code works in quick editor but gets an A2008 error in Visual Studio because of the angled brackets to initialize the struct:

.386
.model flat, stdcall
.stack 4096
.data

hFile         dd      0
htest        MODULEENTRY32 <>

.code
main:
end main
Title: Re: Initializing STRUCT in visual studio doesn't work
Post by: Grincheux on January 23, 2016, 06:13:46 AM
Try

htest        MODULEENTRY32 <?>

Take a look at https://msdn.microsoft.com/en-us/library/afzk3475.aspx?f=255&MSPPError=-2147217396
And this one : http://people.sju.edu/~ggrevera/arch/references/MASM61PROGUIDE.pdf
Title: Re: Initializing STRUCT in visual studio doesn't work
Post by: Nickmare on January 23, 2016, 06:54:10 AM
<?> has the same issue
It is initialized correctly to get the default initializers, so I'm not sure why this error occurs in visual studio. It seems like that syntax isn't allowed in VS, but I need to use it.
Title: Re: Initializing STRUCT in visual studio doesn't work
Post by: qWord on January 23, 2016, 06:58:05 AM
Quote from: Nickmare on January 23, 2016, 06:09:44 AM
The following code works in quick editor but gets an A2008 error in Visual Studio because of the angled brackets to initialize the struct
The initialization is OK - make sure that the structure is declared (by using the corresponding includes).
Title: Re: Initializing STRUCT in visual studio doesn't work
Post by: hutch-- on January 23, 2016, 12:01:38 PM
Something you should not do is use the old DOS .STACK setting, in 32 bit PE files that stack size is set by the linker. Sorry but I don't use VC/VS so I personally cannot help you with the structure notation. Just make sure you have the structure in the include file you use in VC/VS.
Title: Re: Initializing STRUCT in visual studio doesn't work
Post by: Grincheux on January 23, 2016, 05:03:10 PM
QuoteITEMS STRUCT
Iname BYTE 'Item Name'
Inum WORD ?
UNION ITYPE ; UNION keyword appears first
oldtype BYTE 0 ; when nested in structure.
newtype WORD ? ; (See "Nested Structures
ENDS ; and Unions," following ).
ITEMS ENDS
.
.
.
.DATA
Item1 ITEMS < > ; Accepts default initializers
Item2 ITEMS { } ; Accepts default initializers
Item3 ITEMS <'Bolts', 126> ; Overrides default value of first
; 2 fields; use default of
; the third field
Item4 ITEMS { \
'Bolts', ; Item name
126 \ ; Part number
}

Page 98 of the pdf link I send below (MASM 6.1 Manual)