Hello everybody,
I want to be able to define a structure so that I can access data immediately after the structure as a field of the structure.
Example
I want to be able to access the file name string like in the call to CreateFile. Anyone know how I can accomplish this? I checked the documentation with the MASM 7 package, but it doesn't really say if or how to do this
Thanks
--Chorus
I want to be able to define a structure so that I can access data immediately after the structure as a field of the structure.
Example
AFile STRUCT
hFile dd ?
szFileName LABEL BYTE <---won't work btw
AFile ENDS
.data
MyFile AFile <?>
db "filename.txt",0
.code
invoke CreateFile,addr MyFile.szFileName,etc
mov MyFile.hFile,eax
I want to be able to access the file name string like in the call to CreateFile. Anyone know how I can accomplish this? I checked the documentation with the MASM 7 package, but it doesn't really say if or how to do this
Thanks
--Chorus
<snipped old contents>
Here's a similar topic: http://www.asmcommunity.net/board/index.php?topic=8419 (2nd solution)
Here's a similar topic: http://www.asmcommunity.net/board/index.php?topic=8419 (2nd solution)
Thanks Stryker, but neither solution presented seems to fit the bill quite.
The second solution would be what I'm currently doing. What I don't like about this is the fact that I have to name every string, and furthermore, store a pointer to a fixed memory location which is a waste of 4 bytes. Although 4 bytes isn't a lot, I think it would be nice to save it, and furthermore, have the convenience of accessing the string as a member of the structure.
The closest I can come up with is this:
Not exactly elegant ;)
Thanks again
--Chorus
The second solution would be what I'm currently doing. What I don't like about this is the fact that I have to name every string, and furthermore, store a pointer to a fixed memory location which is a waste of 4 bytes. Although 4 bytes isn't a lot, I think it would be nice to save it, and furthermore, have the convenience of accessing the string as a member of the structure.
The closest I can come up with is this:
MyFile STRUCT
hFile dd ?
szFileName db 0
MyFile ENDS
AFile MyFile <0,"M">
db "yFileName.txt",0
Not exactly elegant ;)
Thanks again
--Chorus
How about:
That will put the address of MySting into the STRUCT AT assemble time...
or maybe:
At assemble time a pointer is setup to a stringtable, and optinally you can setup the table at assemble time to be set to string you want to use.
I'm not exactly sure what you are trying to do, and I'm kinda dizzy right now.....
MyFile STRUCT
hFile dd ?
szFileName offset MyString
MyFile ENDS
That will put the address of MySting into the STRUCT AT assemble time...
or maybe:
MyFile STRUCT
hFile dd ?
szFileName offset StringTable
MyFile ENDS
StringTable:
Str1Ptr dd 0 ;StringTable+0
Str2Ptr dd 0 ;StringTable+4
Str3Ptr dd 0 ;StringTable+8
;or
Str1Ptr dd offset (some string)
Str2Ptr dd offset (some string)
Str3Ptr dd offset (some string)
etc.
At assemble time a pointer is setup to a stringtable, and optinally you can setup the table at assemble time to be set to string you want to use.
I'm not exactly sure what you are trying to do, and I'm kinda dizzy right now.....
not elegant??? Third solution - http://www.asmcommunity.net/board/index.php?topic=8419 :)
Maybe you need a new macro for structures that will accept dynamic size and dynamic initialization... You know what I mean... ;)
I'll post some macros if I can come up something.
Maybe you need a new macro for structures that will accept dynamic size and dynamic initialization... You know what I mean... ;)
I'll post some macros if I can come up something.
hm, in tasm you can do it like this:
...
DATASEG
STRUC MyStruc
member1 dd ?
member2 dd ?
member3 dd ?
LABEL data
ENDS
structest MyStruc<1,2,3>
db "just a test",0
CODESEG
Main:
lea eax,[structest.data]
...
In MASM you cheat: :grin:
TestS STRUCT
x1 DWORD ?
x2 DWORD ?
x3 DWORD ?
; _x LABEL BYTE
_x BYTE 0 dup (?)
TestS ENDS
_DATA SEGMENT
mTest TestS <1,2,3>
BYTE "What a load of ____!",0
_DATA ENDS
lea eax, mTest._x
Well I'll be damned!
Thanks bitRAKE that's exactly what I was looking for!
--Chorus
Thanks bitRAKE that's exactly what I was looking for!
--Chorus