Factfinder Posted July 27, 2016 Share Posted July 27, 2016 (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 July 27, 2016 by Factfinder Link to comment Share on other sites More sharing options...
JohnOne Posted July 27, 2016 Share Posted July 27, 2016 first, swap these lines of code _ArrayDisplay($aRet) If @error Or Not $aRet[0] Then Return SetError(@error, @extended, '') AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Factfinder Posted July 27, 2016 Author Share Posted July 27, 2016 (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 July 27, 2016 by Factfinder Link to comment Share on other sites More sharing options...
Factfinder Posted July 27, 2016 Author Share Posted July 27, 2016 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. Link to comment Share on other sites More sharing options...
AutoBert Posted July 28, 2016 Share Posted July 28, 2016 _WinAPI_GetErrorMessage is in WinAPIDiag.au3 so make a bug ticket if it didn't work correct. Link to comment Share on other sites More sharing options...
LarsJ Posted July 28, 2016 Share Posted July 28, 2016 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. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
JohnOne Posted July 29, 2016 Share Posted July 29, 2016 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. Link to comment Share on other sites More sharing options...
Factfinder Posted July 29, 2016 Author Share Posted July 29, 2016 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. Link to comment Share on other sites More sharing options...
water Posted July 29, 2016 Share Posted July 29, 2016 (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 July 29, 2016 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Factfinder Posted July 29, 2016 Author Share Posted July 29, 2016 (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 July 29, 2016 by Factfinder Typo Link to comment Share on other sites More sharing options...
water Posted July 29, 2016 Share Posted July 29, 2016 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Factfinder Posted July 29, 2016 Author Share Posted July 29, 2016 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. Link to comment Share on other sites More sharing options...
water Posted July 29, 2016 Share Posted July 29, 2016 -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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Factfinder Posted July 29, 2016 Author Share Posted July 29, 2016 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. Link to comment Share on other sites More sharing options...
Factfinder Posted July 29, 2016 Author Share Posted July 29, 2016 The MSDN funtion is here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx The flag value 0x1000 is FORMAT_MESSAGE_FROM_SYSTEM Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now