Hi,
I'm Using GoAsm and am having trouble with a call to HeapAllocate.
I've called HeapCreate successfully, and am using the address returned from that in the call to HeapAlloc.
I am not getting an error, the routine assembles and links OK but HeapAlloc always returns 0.
I'm out of ideas on what I may be doing wrong, hopefully someone here can help :)
Code Snippet shown below.
cheers
Jamie
CODE SECTION
start:
push 0
call GetModuleHandleA
mov , eax
push 16384
push 0
push 0
call HeapCreate
CMP eax,0
JE >Error
MOV d ,eax
mov eax,ADDR _STR0
push ebx
push eax
pop ebx
push eax
call lstrlenA
inc eax
push eax
push 8
push
call HeapAlloc
cmp eax,0
je >Error
push ebx
push eax
call lstrcpyA
cmp eax,0
je >Error
mov d, eax
Pop Ebx
Push
mov eax,ADDR _STR1
push eax
mov eax,d
push eax
Push 0
call MessageBoxA
jmp >Exit
Error: push
mov eax,ADDR ErrorTitle
push eax
mov eax,ADDR ErrorMess
push eax
push 0
call MessageBoxA
Exit: push
call HeapDestroy
push 0
call ExitProcess
DATA SECTION
_STR0: db "A Message", 0
_STR1: db "Message", 0
A dw ?
B dd 0
HeapHandle dd 0
Hwnd dd 0
ErrorMess db "An Error Occurred!", 0
ErrorTitle db "Error!", 0
I'm Using GoAsm and am having trouble with a call to HeapAllocate.
I've called HeapCreate successfully, and am using the address returned from that in the call to HeapAlloc.
I am not getting an error, the routine assembles and links OK but HeapAlloc always returns 0.
I'm out of ideas on what I may be doing wrong, hopefully someone here can help :)
Code Snippet shown below.
cheers
Jamie
CODE SECTION
start:
push 0
call GetModuleHandleA
mov , eax
push 16384
push 0
push 0
call HeapCreate
CMP eax,0
JE >Error
MOV d ,eax
mov eax,ADDR _STR0
push ebx
push eax
pop ebx
push eax
call lstrlenA
inc eax
push eax
push 8
push
call HeapAlloc
cmp eax,0
je >Error
push ebx
push eax
call lstrcpyA
cmp eax,0
je >Error
mov d, eax
Pop Ebx
Push
mov eax,ADDR _STR1
push eax
mov eax,d
push eax
Push 0
call MessageBoxA
jmp >Exit
Error: push
mov eax,ADDR ErrorTitle
push eax
mov eax,ADDR ErrorMess
push eax
push 0
call MessageBoxA
Exit: push
call HeapDestroy
push 0
call ExitProcess
DATA SECTION
_STR0: db "A Message", 0
_STR1: db "Message", 0
A dw ?
B dd 0
HeapHandle dd 0
Hwnd dd 0
ErrorMess db "An Error Occurred!", 0
ErrorTitle db "Error!", 0
Hi Codebyter
Seem like you are creating a heap with initially no size and a max size of 16384 bytes
Try doing this instead:
push 0
push 16384
push 0
call HeapCreate
This creates a heap with an initial size of 16384 bytes and unlimitted growth.
KetilO
Seem like you are creating a heap with initially no size and a max size of 16384 bytes
Try doing this instead:
push 0
push 16384
push 0
call HeapCreate
This creates a heap with an initial size of 16384 bytes and unlimitted growth.
KetilO
Hi KetilO,
Thanks for that, unfortunately it still doesn't work.
I've run it through a debugger and can see that the HeapCreate works and returns an address but I can't see what is stopping the HeapAlloc working.
If you want to assemble and run the example I posted you'll need GoAsm from http://www.GoDevTool.com.
The commands I use to compile are:
GoAsm test.asm
golink test.obj kernel32.dll user32.dll
Thanks for your help.
Jamie
Thanks for that, unfortunately it still doesn't work.
I've run it through a debugger and can see that the HeapCreate works and returns an address but I can't see what is stopping the HeapAlloc working.
If you want to assemble and run the example I posted you'll need GoAsm from http://www.GoDevTool.com.
The commands I use to compile are:
GoAsm test.asm
golink test.obj kernel32.dll user32.dll
Thanks for your help.
Jamie
Hi Codebyter
Don't know about GoAsm but using MASM works just fine.
KetilO
Don't know about GoAsm but using MASM works just fine.
KetilO
Well, over the weekend I tried that piece of code on another machine and it worked perfectly.
I still don't know why it won't work on this one, but at least I know the code is correct.
Just for information, it works on a PIII running WinXP Professional but not on a PII running WinNT 4.
Wierd huh.
Jamie
I still don't know why it won't work on this one, but at least I know the code is correct.
Just for information, it works on a PIII running WinXP Professional but not on a PII running WinNT 4.
Wierd huh.
Jamie