OK, i am attempting to write a custom control. Well this is my problem. I have a struct with member inside and 1 of them is an pointer to a returned value from Heapalloc. This is suppose to be my dynamically allocated array that will contain a maximum of 40 items. This array's first element is the counter to work out the length of the array and also the number of assigned buttons in the control. Now i wander into the darker areas of my assembler capabilities. I can only seem to load into the first DWORD part of the array. I have used HEAP_ZERO_MEMORY to make it clear that i am not overwriting some data. So well here is a snippit of code.


assume ebx:PTR WhistlerMenu
.IF lParam!=NULL
invoke GetProcessHeap
.IF [ebx].arrayButton==NULL
push eax
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,8
mov [ebx].arrayButton,eax
pop eax
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,sizeof WhistlerMenuItem
[b]mov ecx,[ebx].arrayButton ;attemptin to save value into second DWORD in array
mov [ecx+4],eax[/b]
.ELSE
mov ecx,4
mov eax,[[ebx].arrayButton]
inc eax
mul eax
pop ecx
invoke HeapReAlloc,ecx,NULL,[ebx].arrayButton,eax
.IF eax==NULL
ret
.ENDIF
mov [ebx].arrayButton,eax
.ENDIF
;find pointer in array,
;copy struct members into struct pointed by array pointer
[b]inc DWORD PTR [[ebx].arrayButton][/b] ;increase the first element to reflect the # of buttons
.ENDIF


And the last instruction is the one that seems to be overwriting some data.

If there is a better way to achieve this can you please tell me how - or why cant i write to the second DWORD in the array?
PS: i have zero'ed the struct so that debugging is easier.

took away the message box call - was for me to see if the function got called
Posted on 2004-07-26 04:15:57 by Black iCE
Haven't gone into any depth of your logic but there is one obvious problem with your code: there is no push for your pop ecx

Antonis
Posted on 2004-07-26 04:22:33 by akyprian
Thank you, akyprian.

This would have been a future problem. I forgot to mention that the first if statement is taken. The else is for later - haven't got that far yet.
Posted on 2004-07-26 04:26:27 by Black iCE
If you could post your project, then I could be of more help

Antonis
Posted on 2004-07-26 04:34:43 by akyprian
Well *imbaressed* - i am in the VERY beginnig stages, but have a look.

Thank you, akyprian.

PS: WinAsm Studio is great.:alright:

remove attachment - as i said it is in the very beginning stages, no use of waisting space:grin:
Posted on 2004-07-26 04:40:01 by Black iCE
akyprian, thank you for looking @ it. i have gotten it working.


assume ebx:PTR WhistlerMenu
.IF lParam!=NULL
invoke GetProcessHeap
.IF [ebx].arrayButton==NULL
push eax
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,8
mov [ebx].arrayButton,eax
pop eax
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,sizeof WhistlerMenuItem
mov ecx,[ebx].arrayButton
mov [ecx+4],eax
.ELSE
mov ecx,4
mov eax,[[ebx].arrayButton]
inc eax
mul eax
invoke HeapReAlloc,ecx,NULL,[ebx].arrayButton,eax
.IF eax==NULL
ret
.ENDIF
mov [ebx].arrayButton,eax
.ENDIF
mov ecx,[ebx].arrayButton
inc DWORD PTR [ecx]


Looks like you can't use [.y], you cant referer to a value in that santax - it will compile and take .y and not to what it reffers to. Thanks anyway.

Idoit @ work - sorry:grin:
Posted on 2004-07-26 05:05:32 by Black iCE
Here is an alternative.

Antonis

PS. Needs a lot of clearing/testing. Look at XPM_INSERTITEM, test your WM_DESTROY if you are going to take this approach

Antonis
Posted on 2004-07-26 05:52:54 by akyprian
Thank you akyprian.
I see what you have done. Seems simple enough.

Black iCE
Posted on 2004-07-26 06:03:35 by Black iCE