The MASM Forum

Miscellaneous => Miscellaneous Projects => Windows Projects => Topic started by: TouEnMasm on November 29, 2015, 04:20:09 AM

Title: dll to show the winerror message (winerror.h)
Post by: TouEnMasm on November 29, 2015, 04:20:09 AM
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

Title: Re: dll to show the winerror message (winerror.h)
Post by: jj2007 on November 29, 2015, 04:55:39 AM
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
Title: Re: dll to show the winerror message (winerror.h)
Post by: dedndave on November 29, 2015, 05:27:38 AM
need a DLL for that ?   :redface:
Title: Re: dll to show the winerror message (winerror.h)
Post by: TouEnMasm on November 29, 2015, 05:43:23 AM
"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.
Title: Re: dll to show the winerror message (winerror.h)
Post by: jj2007 on November 29, 2015, 06:02:06 AM
The errors are in the message tables:

include \masm32\MasmBasic\MasmBasic.inc      ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  wMsgBox (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1253) 0, MsgTable$ (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1106)(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.
Title: Re: dll to show the winerror message (winerror.h)
Post by: TouEnMasm on November 29, 2015, 06:32:57 AM
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
     


Title: Re: dll to show the winerror message (winerror.h)
Post by: jj2007 on November 29, 2015, 06:47:30 AM
No such error at the link you provided.
Title: Re: dll to show the winerror message (winerror.h)
Post by: dedndave on November 29, 2015, 06:57:35 AM
i think errors with bit 31 set are handled differently
i don't remember the details   :(
Title: Re: dll to show the winerror message (winerror.h)
Post by: TouEnMasm 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

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
Title: Re: dll to show the winerror message (winerror.h)
Post by: jj2007 on November 29, 2015, 07:44:58 PM
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
Title: Re: dll to show the winerror message (winerror.h)
Post by: TouEnMasm on November 30, 2015, 01:03:02 AM
:icon_exclaim: