Factfinder

_WinAPI_GetErrorMessage works fully on Win 10 but partially on other Windows

15 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm having a hard time getting the function fully to work on other Windows than Windows:

$ret = _WinAPI_GetErrorMessage('1058')
MsgBox(0,'1', '"' & $ret & '"')
$ret = _WinAPI_GetErrorMessage('-2140993535')
MsgBox(0,'2', '"' & $ret & '"')


Func _WinAPI_GetErrorMessage($iCode, $iLanguage = 0)
    Local $aRet = DllCall('kernel32.dll', 'dword', 'FormatMessageW', 'dword', 0x1000, 'ptr', 0, 'dword', $iCode, _
            'dword', $iLanguage, 'wstr', '', 'dword', 4092, 'ptr', 0)           
    If @error Or Not $aRet[0] Then Return SetError(@error, @extended, '')
    Return StringRegExpReplace($aRet[5], '[' & @LF & ',' & @CR & ']*\Z', '')
EndFunc   ;==>_WinAPI_GetErrorMessage

The first error code (the plus code 1058) will be returned correctly on all Windows.
The second error code (the minus code -2140993535) will be returned correctly only on Windows 10.

Is there a way to make the function work on other Windows versions for minus error codes? Or is there any other way to get the error message using Autoit?

Thanks in advance.

Edited by Factfinder

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

34 minutes ago, JohnOne said:

first, swap these lines of code

 _ArrayDisplay($aRet)
    If @error Or Not $aRet[0] Then Return SetError(@error, @extended, '')

I removed the line. However, I had put it there because the function didn't return any extended error.

I edited the script to avoid any confusion. Thank you.

Edited by Factfinder

Share this post


Link to post
Share on other sites

BTW;   this is part of the function:

 If @error Or Not $aRet[0] Then Return SetError(@error, @extended, '')

Swapping it doesn't make any difference.

Share this post


Link to post
Share on other sites
_WinAPI_GetErrorMessage

is in WinAPIDiag.au3 so make a bug ticket if it didn't work correct.

Share this post


Link to post
Share on other sites

Easy now. In each new version of the Windows operating system there are added hundreds or thousands of new error codes and corresponding error messages. The number of error codes and error messages is always increasing.

Why do you expect that all error codes and error messages in Windows 10 also exists in Windows 7? This is a wrong assumption. But the reverse is probably true. All error codes in Windows 7 is also registered in Windows 10.

Share this post


Link to post
Share on other sites
11 hours ago, LarsJ said:

Easy now. In each new version of the Windows operating system there are added hundreds or thousands of new error codes and corresponding error messages. The number of error codes and error messages is always increasing.

Why do you expect that all error codes and error messages in Windows 10 also exists in Windows 7? This is a wrong assumption. But the reverse is probably true. All error codes in Windows 7 is also registered in Windows 10.

They've always been there but developers want more and more access to the OS in order to bring a better personal experience to the user.

(or so they say)

They/We want to know what went wrong and why. And so with each new generation of windows, they give the info, usually in dll's, and soon only in that cloud.

Point is, the error codes expand because you and I, demand it.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
20 hours ago, LarsJ said:

Easy now. In each new version of the Windows operating system there are added hundreds or thousands of new error codes and corresponding error messages. The number of error codes and error messages is always increasing.

Why do you expect that all error codes and error messages in Windows 10 also exists in Windows 7? This is a wrong assumption. But the reverse is probably true. All error codes in Windows 7 is also registered in Windows 10.

Not sure how you came to your assumtion, both the error codes are generated by Windows 7. None of them is confined to Window 10. They were there even before Windows 10 existed.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

This two lines work on W7:

$ret = _WinAPI_GetErrorMessage(0x80020009) ; Exception occurred
$ret = _WinAPI_GetErrorMessage(2147614729) ; Same but decimal. Note that it is a positive value. -2147614729 returns nothing

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I had converted my second error code to hex before applying the funtion and it did not work on Windows 7. And on Windows 10 either way works.

In fact we probably don't need to convert the negative code to hex. I have checked it and both Windows versions convert the ngative code to identical positive number.

 

 

 

 

 

Edited by Factfinder
Typo

Share this post


Link to post
Share on other sites

I tried

$ret = _WinAPI_GetErrorMessage('-2140993535')

with dec and hex. And it doesn't return an error message on W7. As it returns a message for other codes I assume it is a message code that does not exist on W7.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Since the error code is generated by Windows 7, I hope the error message can be obtained from it too. Or we have to be sure before giving it up.

I have played with other values than x1000 as the flag value. 

 

 

Share this post


Link to post
Share on other sites
-2140993535 (decimal) or 0x80630801 hex) stands for: PEER_E_CERT_STORE_CORRUPTED The certstore is corrupted.
https://msdn.microsoft.com/en-us/library/windows/desktop/hh404142(v=vs.85).aspx
 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thank you but I kow that already as on Winsows 10 the error message is returned correcly. :)

My aim is to get the funcion to work on previous Windows version.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now