Hi, i was wondering if anyone know how to display result after calling
invoke GetLastErrot
in MessageBox or something like that, i dont know how to set that in buffer or something like that?
anyone help me?
Thanks :U
Have a look at the FormatMessage API.
ErrorToString FRAME dwErrorCode,pString,cbString
mov eax,[dwErrorCode]
or eax,eax
jnz >
call GetLastError
:
invoke FormatMessageA,1000h,0,eax,0,[pString],[cbString],0
RET
ENDF
dwErrorCode can be NULL in which case the last error code is used. pString should point to a buffer of at least 64 bytes, cbString contains the size of the buffer.
Donkey
wow, thank you donkey, now seems to be easy, i was dont know about FormatMessage api etc...
Thanks :U
trodon,
Try this one out of the masm32 macro collection, it is documented in the High level help file.
print LastError$(),13,10
; or in GUI mode.
fn MessageBox,hWnd,LastError$(),"The last error was ..."",MB_OK
This one print the message in the native language of the computer.
eax is not send so you have to put it immediately after the error occured.
The title of the messagebox is needed ,that all.
ToutEnMasm
RetrouveMessageErreur proc lpTitle:DWORD
LOCAL lpMsgBuffer : LPVOID
; 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 ecx ; our language ID, calculated above
invoke 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
ret
RetrouveMessageErreur endp