To use it as one of proc from masm32.lib:
1. Save the code as file with .asm extention in
M32lib folder
2. Add string to in the folder:
GetErrDescription PROTO :DWORD
3. Run make.bat
The proc is primary for developing and cathcing errors
it's easy to insert just a line of code calling it when something
going wrong to get description of the error.
And it reasonably short (though add couple bytes to .data
and fast.

Here it is:

.model flat,stdcall
option casemap:none
include C:\masm32\include\
include C:\masm32\include\
include C:\masm32\include\

;The Proc will produce MsgBox with Last error number and description
;GetErrDescription, ErrNum if ErrNum = 0 the procedure call GetLastError to obtain LastErrorNumber
;If you already know the error number (for Example WNetAddConnection2 return 0 on seccess and
;Error number when failes) pass it as ErrNum
;invoke WNetAddConnection2,offset nr,offset Pass,0,CONNECT_UPDATE_PROFILE
;or eax,eax
;jne GetErr
;..... ;code if OK
; invoke GetErrDescription,eax
;When you don't get the error code pass 0 as parameter
; Example:
; invoke LocalFree,1234
;jne OK ;0 if error
;invoke GetErrDescription,eax ;eax=0
ErrMsgTmpl db 'Error Code %i',13,10
db 'Description: %s',0
Unknown db 'UnKnownError',0
GetErrDescription proc uses ebx edi ErrNum:DWORD
LOCAL Buffer[256]:BYTE

mov eax,ErrNum
or eax,eax
jne WeAlreadyKnowIt
invoke GetLastError

mov edi,eax
0, ;GetItFromSystem
edi,0, ;ErrNum,Default language
addr hLocal, ;where to send the address of string from system
0,0 ; any size, no arguments
or eax,eax ;
mov ebx,offset UnKnown
je UnKnown
invoke LocalLock,hLocal
mov ebx,eax
invoke wsprintf,addr Buffer,offset ErrMsgTmpl,edi,ebx
invoke MessageBox,0,addr Buffer,0,0
cmp ebx,offset UnKnown
je @F
invoke LocalFree,hLocal
GetErrDescription endp
Posted on 2001-08-14 06:34:50 by The Svin

I copied the proc and built it and it runs OK but I get an unusual result from it on success in the piece I tested with.

stralloc -1 ; 100000
mov var, eax

; invoke GetErrDescription, eax

strfree var

I tested between the macro "ShowlastError" and the new module "GetErrDescription".

Both yield error 127 for the error but if I cange the memory alocation to a positive value, the MACRO returns error 0 SUCCESS where the proc returns error code 4259964
Description: SWh3@

I don't know what is happening here.

PS: I would post the file rather than the just the code as the PHP messes up the formatting in Netscape and its hard to read the file as it is copied .

Posted on 2001-08-14 14:37:30 by hutch--
Steve, I'haven't quite understood you.
I think, it because of my English.
What do you mean by changing memory location?

But at least I have couple things in mind to say.
The proc has some unusual approach -
it should be called only if an error occured.
Since it treat 0 in parameter as command to call
GetLastError itself, assuming that the calling code doesn't
retreave the error code yet (you know there are lots of APIs
func. that returned zero if failed and apps need to call
GetLastError to get exact code)
For the above it would never discribe any success codes
since they all have actually zero value.

I'm not sure that it helps to your post, at least I tried to make a move in the darkness :)

The other thing (not relative to your post - just thoughts about the proc) - there are ways to describe more errors actully then
from system.
1. Error code may have some values description on which is
in netmsg.dll (they all related to net and it means that you
can get some net related error descriptions from system but
some of them described only in netmsg.dll.

2. There are also net messages descriptions you can only get through
WNetGetLastError function. but this means that to use
the proc use needs to include mpr.lib in the source.

Anyway I can easily change the proc so that if Error Code is unkown to the system, it would try to get description from
netmsg.dll and through WNetGetLastError.

What do you think?
Posted on 2001-08-15 01:32:18 by The Svin
I think, I can explain now.
There is actually such an error code, though I have no Idea what it means SWh :)
But if there were not such an error FormatMessage would have returned 0, but it didn't - I explicatly call it with 4259964
as immediate parameter and it returned with the same result as you had.
Zero as parameter is treated by the proc as request for
the proc to call GetLastError
The last error was 0, and after that 4259964 set.
It did the proc comftable for myself :)
So if some function doesn't fail, dont call the proc.
Call it only when function upon return indicate that there was
errow (with 0 as parameter) or when you know the code
and can send it as immediate or if your code somehow obtained the code other then 0(success).
Posted on 2001-08-15 04:59:26 by The Svin