News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Display error!.

Started by trodon, November 12, 2006, 02:37:59 AM

Previous topic - Next topic

trodon

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

sinsi

Have a look at the FormatMessage API.
Light travels faster than sound, that's why some people seem bright until you hear them.

donkey

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
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

trodon

wow, thank you donkey, now seems to be easy, i was dont know about FormatMessage api etc...
Thanks  :U

hutch--

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


Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ToutEnMasm

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