Hi i'm new to the forum and im struggling to find a solution to a problem im having
i have been trying to create structs and call them correctly however i dont seem to be able to get it to compile
i could do with a few links to tutorials that cover this or an example that i can follow to see where im going wrong
i need a struct that is recursive eg
mystruct STRUCT DWORD
next mystruct ?
value DWORD ?
mystruct ENDS
have i made any mystakes here?
i also would like an example of the code that can set both values correctly and pass these values correctly to other procs
please help i haven't done any coding in assembler for years and its all changed.
p.s. know any good profilers debuggers that display your own source as they step through the programs?
cheers flipflop
you can not use a structure inside it's definition:
mystruct STRUCT DWORD
next PVOID ?
value DWORD ?
mystruct ENDS
if that is the case how would i go about creating a dynamic tree or list
Quote from: flipflop on December 17, 2011, 01:30:20 AM
if that is the case how would i go about creating a dynamic tree or list
as shown: use pointers
mystruct STRUCT DWORD
next PVOID ? ; pointer to next node/element. PVOID == DWORD == 32Bit
value DWORD ?
mystruct ENDS
cheers
ill give that a try
ok so i have my struct
mystruct STRUCT DWORD
next PVOID ?
value DWORD ?
mystruct ENDS
and im setting the value using
initmystruct proc mystruct:PVOID
mov eax,mystruct
mov (mystruct PTR [eax]).value,0
mov (mystruct PTR [eax]).next,0
ret
initmystruct endp
this compiles but crashes
ive read some where that the angle brackets make no difference :red
The code is OK - propably you are passing an invalid pointer to the function.
You may show us your full code.
Quote.386
.model flat, stdcall
option casemap :none
include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib
initmystruct proto :DWORD
mystruct STRUCT
next PVOID ?
value DWORD ?
mystruct ENDS
.data
.data?
.code
start:
invoke ExitProcess,0
initmystruct proc mystruct1:PVOID
assume eax:ptr mystruct
mov eax, mystruct1
mov [eax].value,0
mov [eax].next,0
assume eax:nothing
ret
initmystruct endp
end start
thankyou bomz
much better than what i had wrote. very helpful
scanner proc bufferptr:DWORD,buffersize:DWORD
LOCAL mystruct :PVOID
invoke initmystruct,mystruct
.....more code that does not get executed.......
ret
scanner endp
this is the code fragment that causes the crash (i put print statements all through my code to find this)
Quote from: flipflop on December 17, 2011, 03:23:41 PM
this is the code fragment that causes the crash (i put print statements all through my code to find this)
Presumably because you need to be passing the address of an actual structure to fill, not a pointer to a pointer, or an empty pointer.
This in form which make code much READABLE, but mean this:
Quoteinitmystruct proc mystruct1:PVOID
mov dword ptr[mystruct1],0
mov dword ptr[mystruct1+4],0
ret
initmystruct endp
Your variable mystruct (which has the same name as the structure?), is not initialized.
...
LOCAL pMystruct:PVOID
mov pMyStruct,alloc(SIZEOF MYSTRUCT) ; allocate new structure
invoke initmystruct,pMyStruct
...
or
...
LOCAL Mystruct:MYSTRUCT
invoke initmystruct,ADDR Mystruct ; pass pointer to structure
...
MASM has several syntax variantion for accessing structure members through pointers. A common way is: [register].STRUCTURENAME.member
cheers brilliant just what i was looking for very helpful indeed thankyou everyone for replies :U