I had converted this from the MASM code(Meaning I didn't do the original). If I declare the lpMsgBuffer up in the data section it works just fine. What I am tring to do now is, be able to not have to remember to do this in every program.



proc HandleError, lpTitle
lpMsgBuffer dd ?
enter

; calculate language ID, asm version of MAKELANGID
mov cx, SUBLANG_DEFAULT
shl ecx, 10
;or cx, LANG_NEUTRAL ; LANG_NEUTRAL = 0, nothing necessary

; Setup parameters for FormatMessage, normal pushing to use some
; params directly (e.g. GetLastError returns the ID in eax, but I
; can't use this register in "invoke")

push NULL ; we don't need this
push 0 ; min. size of output buffer if we use
; FORMAT_MESSAGE_ALLOCATE_BUFFER
; lea eax, lpMsgBuffer ; get address of our buffer
; push eax ; address of buffer

push lpMsgBuffer

push ecx ; our language ID, calculated above
call [GetLastError] ; get error number
push eax ; push return value = error ID
push NULL ; can be used to format a string, we don't need it
mov edx, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM
push edx ; some flags, check your doc for more
call [FormatMessage] ; here we go

; Display error-message
invoke MessageBox, NULL, [lpMsgBuffer], [lpTitle], MB_OK or MB_ICONSTOP

; free memory
invoke LocalFree, [lpMsgBuffer]

return

leave
Posted on 2003-01-07 16:04:00 by jInuQ
Shouldn't there be:


lea eax, [lpMsgBuffer]
push eax

instead of "push lpMsgBuffer"?
Posted on 2003-01-07 16:18:23 by Tomasz Grysztar
That's the thing, when i do:


section '.data' data readable writeable
lpMsgBuffer dd ?

section '.code' code readable executable
proc HandleError, lpTitle
enter

; calculate language ID, asm version of MAKELANGID
mov cx, SUBLANG_DEFAULT
shl ecx, 10
;or cx, LANG_NEUTRAL ; LANG_NEUTRAL = 0, nothing necessary

; Setup parameters for FormatMessage, normal pushing to use some
; params directly (e.g. GetLastError returns the ID in eax, but I
; can't use this register in "invoke")

push NULL ; we don't need this
push 0 ; min. size of output buffer if we use
; FORMAT_MESSAGE_ALLOCATE_BUFFER
; lea eax, lpMsgBuffer ; get address of our buffer
; push eax ; address of buffer

push lpMsgBuffer

push ecx ; our language ID, calculated above
call [GetLastError] ; get error number
push eax ; push return value = error ID
push NULL ; can be used to format a string, we don't need it
mov edx, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM
push edx ; some flags, check your doc for more
call [FormatMessage] ; here we go

; Display error-message
invoke MessageBox, NULL, [lpMsgBuffer], [lpTitle], MB_OK or MB_ICONSTOP

; free memory
invoke LocalFree, [lpMsgBuffer]

return

leave

And do it like this it works.
Posted on 2003-01-07 16:23:15 by jInuQ
You can also use this macro from the latest FASMW includes:


macro push arg
{ if _#arg in <_addr arg,_ADDR arg>
local ..arg,..op
label ..arg at arg
virtual at 0
mov eax,..arg
load ..opcode from 0
end virtual
if ..opcode = 0A1h
push arg
else
lea edx,..arg
push edx
end if
else if +arg eq arg | arg +0 eq arg 0
push arg
else
local ..continue
call ..continue
db arg,0
..continue:
end if }

And then do:


push ADDR [lpMsgBuffer]
Posted on 2003-01-07 16:45:15 by Tomasz Grysztar
Doing lea eax, works.

Thanks for the help.
Posted on 2003-01-07 23:16:37 by jInuQ