News:

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

WinError.h bug?

Started by vitsoft, January 16, 2005, 06:47:21 PM

Previous topic - Next topic

vitsoft

The high word of error code returned by GetLastError() is a facility code,
which is specified in SDK's WinError.h. From an unknown reason the codes
are sorted descending by name in the header file.
When I sorted them by value, I found out that both FACILITY_SECURITY
and FACILITY_SSPI share the same value of 9.  Isn't it a bug?

I have one more question: is there any WinAPI call which converts
the values obtained from GetLastError to a human readable text?
And if it isn't, what is expanding the formal parameters %1, %2, %3 etc
in messages such as
#define ERROR_WRONG_DISK    34L
//  The wrong diskette is in the drive.
//  Insert %2 (Volume Serial Number: %3)
//  into drive %1.


MichaelW

#1
From the WinError.h included with the February 2003 Platform SDK (in the order that they appear in the header file):

// Define the facility codes
//
#define FACILITY_WINDOWS_CE              24
#define FACILITY_WINDOWS                 8
#define FACILITY_URT                     19
#define FACILITY_UMI                     22
#define FACILITY_SXS                     23
#define FACILITY_STORAGE                 3
#define FACILITY_STATE_MANAGEMENT        34
#define FACILITY_SSPI                    9
#define FACILITY_SCARD                   16
#define FACILITY_SETUPAPI                15
#define FACILITY_SECURITY                9
#define FACILITY_RPC                     1
#define FACILITY_WIN32                   7
#define FACILITY_CONTROL                 10
#define FACILITY_NULL                    0
#define FACILITY_METADIRECTORY           35
#define FACILITY_MSMQ                    14
#define FACILITY_MEDIASERVER             13
#define FACILITY_INTERNET                12
#define FACILITY_ITF                     4
#define FACILITY_HTTP                    25
#define FACILITY_DPLAY                   21
#define FACILITY_DISPATCH                2
#define FACILITY_CONFIGURATION           33
#define FACILITY_COMPLUS                 17
#define FACILITY_CERT                    11
#define FACILITY_BACKGROUNDCOPY          32
#define FACILITY_ACS                     20
#define FACILITY_AAF                     18



MSDN: FormatMessage

The error codes are discontinuous so this console app will be terminated after error code 34.

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .486                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    include \masm32\macros\macros.asm

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      lpBuffer dd 0
    .code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    ; *** Will terminate after ID 34 ***
    xor   esi, esi
  @@: 
    invoke FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or \
                          FORMAT_MESSAGE_FROM_SYSTEM or \
                          FORMAT_MESSAGE_IGNORE_INSERTS,
                          0,
                          esi,
                          0,
                          ADDR lpBuffer,
                          0,
                          0
    print ustr$(esi)
    print chr$(" : ")
    print lpBuffer
    invoke LocalFree, lpBuffer
    inc   esi
    ; *** Press enter to continue ***
    mov   eax, input()
    jmp   @B
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

DWORD FormatMessage(
  DWORD dwFlags,
  LPCVOID lpSource,
  DWORD dwMessageId,
  DWORD dwLanguageId,
  LPTSTR lpBuffer,
  DWORD nSize,
  va_list* Arguments
);

eschew obfuscation