News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

dll to show the winerror message (winerror.h)

Started by TouEnMasm, November 29, 2015, 04:20:09 AM

Previous topic - Next topic

TouEnMasm

Hello,
The dll export two functions
Quote
;---------------Arg:error num,title of the message box
;---------- errornum is the same than in winerror.h,sdk 10,windows 10
WinErrorMsg PROTO errornum:DWORD,atitle:DWORD
;----- same usage as GetLastError + show message Arg:title of the message box
GetLastErrorMsg PROTO atitle:DWORD
usage :the dll must be in the local directory or in the c:\windows\system32,C:\Windows\SysWOW64\
include Showerror.inc
includelib Showerror.lib

Fa is a musical note to play with CL

jj2007

Here is a usage example:

include \masm32\include\masm32rt.inc
include Showerror.inc
includelib Showerror.lib

.data
title$ db "This is Yves's macro:", 0

.code
start:
  invoke SetLastError, 33
  MsgBox 0, LastError$(), "Hello, this is a Masm32 macro:", MB_OK or MB_ICONERROR or MB_SETFOREGROUND
  invoke GetLastErrorMsg, addr title$
exit
end start

dedndave


TouEnMasm

"Need a dll for that ?"

sample :GetNamedSecurityInfo
return value
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a nonzero error code defined in WinError.h.

Ok,I have the WinError.sdk,it's beautifull,but .....unusable because in this form
Quote
;
; MessageId: ERROR_VIRUS_INFECTED
;
; MessageText:
;
; Operation did not complete successfully because the file contains a virus or potentially unwanted software.
;
ERROR_VIRUS_INFECTED   equ   < 225>
and getlasterror had a limited range of messages.
Fa is a musical note to play with CL

jj2007

The errors are in the message tables:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  wMsgBox 0, MsgTable$(225, "Kernel32"), "Unicode, extracted from Kernel32.dll:", MB_OK
EndOfCode


See attachment, should work even on a Chinese or Arabic Windows version. No need for a 470k DLL.

TouEnMasm

That's only valid with getlasterror for which the system give a translation with formatmessage .
The <225> message is just here to show the form.

If you prefer there is this one,out of range of getlasterror and not translated
;
; MessageId: UTC_E_TRACE_BUFFER_LIMIT_EXCEEDED
;
; MessageText:
;
; The trace profile needs more memory than is available for tracing
;
UTC_E_TRACE_BUFFER_LIMIT_EXCEEDED   equ   < 087C51027h>

https://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx

surprise:
   invoke SetLastError, 087C51027h   
   invoke GetLastErrorMsg,TXT("ERROR")       ;message in national language
   invoke WinErrorMsg,087C51027h,TXT("WinError") ;message in english
     


Fa is a musical note to play with CL

jj2007


dedndave

i think errors with bit 31 set are handled differently
i don't remember the details   :(

TouEnMasm

I recognize that i have been a little fast to write a dll.
With GetNamedSecurityInfo returning an winerror num message,soluce in API is:
   invoke SetLastError, numwinerror_returned ;087C51027h   
   invoke GetLastErrorMsg,TXT("ERROR")       ;message in national language

The SetLastError is not needed when the function is said using the GetLastError function

Quote
;################################################################
GetLastErrorMsg proc lpTitle:DWORD
   
   LOCAL lpMsgBuffer    : DWORD
   
   ; calculate language ID, asm version of MAKELANGID
   mov cx, SUBLANG_DEFAULT
   shl ecx, 10
   ;or  cx, LANG_NEUTRAL      ; Allow National language deleting the or
   
   ; 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

GetLastErrorMsg endp
Fa is a musical note to play with CL

jj2007

Quote from: ToutEnMasm on November 29, 2015, 05:36:36 PM
I recognize that i have been a little fast to write a dll.
With GetNamedSecurityInfo returning an winerror num message,soluce in API is:
   invoke SetLastError, numwinerror_returned ;087C51027h   
   invoke GetLastErrorMsg,TXT("ERROR")       ;message in national language

Strange, I just see an empty messagebox. Same for
   MsgBox 0, LastError$(), "Masm32 is great:", MB_OK

TouEnMasm

Fa is a musical note to play with CL