Author Topic: dll to show the winerror message (winerror.h)  (Read 2764 times)

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
dll to show the winerror message (winerror.h)
« 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

Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: dll to show the winerror message (winerror.h)
« Reply #1 on: November 29, 2015, 04:55:39 AM »
Here is a usage example:

Code: [Select]
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

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: dll to show the winerror message (winerror.h)
« Reply #2 on: November 29, 2015, 05:27:38 AM »
need a DLL for that ?   :redface:

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: dll to show the winerror message (winerror.h)
« Reply #3 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.
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: dll to show the winerror message (winerror.h)
« Reply #4 on: November 29, 2015, 06:02:06 AM »
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.

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: dll to show the winerror message (winerror.h)
« Reply #5 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
     


Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: dll to show the winerror message (winerror.h)
« Reply #6 on: November 29, 2015, 06:47:30 AM »
No such error at the link you provided.

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: dll to show the winerror message (winerror.h)
« Reply #7 on: November 29, 2015, 06:57:35 AM »
i think errors with bit 31 set are handled differently
i don't remember the details   :(

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: dll to show the winerror message (winerror.h)
« Reply #8 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
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: dll to show the winerror message (winerror.h)
« Reply #9 on: November 29, 2015, 07:44:58 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

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: dll to show the winerror message (winerror.h)
« Reply #10 on: November 30, 2015, 01:03:02 AM »
:icon_exclaim:
Fa is a musical note to play with CL