In the PSDK reference for ILCreateFromPath there is no information how the function behaves when it fails (and, more importantly, how to get extended error information).
What behavior should I expect, and how can I get that error information?
It is not documented anywhere else. If it fails, it returns a NULL pointer, and there is no extended error info available what that happens.
Use SHParseDisplayName() instead (even Microsoft says it is preferred over ILCreateFromPath()). It returns an HRESULT, which contains an error code on failure.
Related
I have build a website run heavy ajax and I'm really care about performance after I enable Strict warning(performance penalty) in firebug it shown me a lot of warning from system and jquery2.2.3 as below image.
Enabling the option Strict Warnings (performance penalty) means that you will also get JavaScript warnings, which are hints about correct usage, though they may not have any effect on the execution of the code.
Examples for this are already shown in your screenshot, like references to undefined variables or using a single equal sign in a statement, which may be a comparison.
Example causing such messages:
while (item = array[i]) {
...
}
In this case item is not declared via var or let before a value is assigned to it, so you'll get a "reference to undefined property" warning. And an assignment is used within the while condition, which will cause a "test for equality (==) mistyped as assignment (=)?" warning.
jQuery and other libraries make a lot of use of such constructs. That's why you see so many messages related to it.
The logs marked with <System> are coming from browser internal code and can be ignored by you. To see them you must also have Show Chrome Errors or Show Chrome Messages.
Using strict means browser will check many things like if variable is initialized before use. There is no syntax error etc
I was unable to find any hint of the exact meaning of the SE_ERR_ASSOCINCOMPLETE ShellExecute return value.
I know that MSDN says "The file name association is incomplete or invalid", but what exactly does that mean? In what situations can it occur?
The best information on this can be found in the documentation. Which supplies the text:
The file name association is incomplete or invalid.
Which is what you've found out. To be honest it seems reasonably clear what it means, specifically that there is something wrong with the file association that has prevented the function from completing.
As to what SE_ERR_ASSOCINCOMPLETE means in full gory detail, that is an exhaustive list of all possible failure modes, you'll likely never find out. This is a deprecated function that exists solely to maintain backwards compatibility. The chances of Microsoft offering more insight into its works are vanishingly small.
The smart play here is not to call ShellExecute. Its error handling is crippled. Instead use ShellExecuteEx. When that fails, use GetLastError to get a Win32 error code.
Read more about that in Raymond Chen's article, Why does ShellExecute return SE_ERR_ACCESSDENIED for nearly everything? And then ask yourself what is the point of trying to gain a full understanding of the error codes that this function returns when most of the time you'll get SE_ERR_ACCESSDENIED.
Are the error codes defined in WinError.h free to be hijacked and returned my by own code?
There are some generic Win32 error codes defined:
ERROR_FILE_NOT_FOUND: "The system cannot find the file specified."
that of course i could use for my own purpose when a file is not found.
Then there are still some generic errors:
ERROR_ACCESS_DENIED: "Access is denied."
but it's generally understood that this error comes when trying to access a file. i might have an HttpGet() function that returns ERROR_ACCESS_DENIED if the server returns a 401.
But then there are codes that are defined as being for a particular purpose. Imagine my HttpGet() function throws an error if the https certificate is not a type we support:
ERROR_IPSEC_IKE_INVALID_CERT_TYPE: "Invalid certificate type"
except that code is defined quite clearly in WinError.h as belonging to IPSec:
///////////////////////////////////////////////////
// //
// Start of IPSec Error codes //
// //
// 13000 to 13999 //
///////////////////////////////////////////////////
...
//
// MessageId: ERROR_IPSEC_IKE_INVALID_CERT_TYPE
//
// MessageText:
//
// Invalid certificate type
//
#define ERROR_IPSEC_IKE_INVALID_CERT_TYPE 13819L
But the error text is exactly what i want!
We have a financial system that requires a 2nd user to approve a transaction; this means that the entered credentials must be a different user than the first person:
MK_E_MUSTBOTHERUSER: "User input required for operation to succeed"
or perhaps:
ERROR_LOGON_TYPE_NOT_GRANTED: "Logon failure: the user has not been granted the requested logon type at this computer."
i get the sense that spelunking through WinError, cherry-picking error codes by the string they show and re-purposing them to indicate errors they were not designed for, is something Raymond would give me a slap for.
Are Windows error codes a freely available "pool" of error codes? Or are all Windows error codes only to be returned from Microsoft's code?
If i'm creating HRESULTS, i need to use some code. And it would be great if the user could call FormatMessage to turn my HRESULT into a string. (Especially since my return HRESULT could either me either my own code, or an HRESULT that was returned to me from Microsoft code).
When you define your own HRESULT codes, you are recommended to use FACILITY_ITF and define your codes in this range of application-defined codes. Yes the codes would overlap between applications, but you can also provide additional descriptive message through SetErrorInfo API and indicating support by implementing ISupportErrorInfo if you are implementing COM object/interface.
An excerpt from COM+ Programming book explains this in greater detail: COM+ programming: a practical guide using Visual C++ and ATL (page 67).
Simpler than that, you can use your custom facility code and this might be different in different modules, so you can easily identify which module is the source of the problem.
If you put MESSAGETABLE resource into your binary, FormatMessage API could resolve HRESULTs and extract description text for individual codes, just like it happens with regular Windows error codes (the app would still need to provide module handle to the API function).
See also: Creating your own HRESULT?
O.P. Edit:
From Microsoft's Open Protocol Specification of HRESULTs
2.1 HRESULT
The HRESULT numbering space is vendor-extensible. Vendors can supply their own values for this field, as long as the C bit (0x20000000) is set, indicating it is a customer code.
C (1 bit): Customer. This bit specifies if the value is customer-defined or Microsoft-defined. The bit is set for customer-defined values and clear for Microsoft-defined values. <1>
<1> Section 2.1: All HRESULT values used by Microsoft have the C bit clear.
This means that i can make up any HRESULT i like as long as i set the C bit. As a practical matter this means that i can any any code i like, e.g.:
E_LOGON_FAILURE = 0xA007052E;
Of course i didn't come up with this number at random.
First i set the high bit to 1, to indicate an error:
0x80000000
Then i "choose" an error code, e.g. 1326 (0x52E hex):
0x8000052E
Then i need to choose a facility. Let's chooooose, on i dunno, seven:
0x8007052E
Finally i set the Customer bit, to indicate it is not a Microsoft defined HRESULT:
0xA007052E
And coincidentally everything up until the last step is the guts of the Microsoft HRESULT_FROM_WIN32 macro:
Maps a system error code to an HRESULT value.
HRESULT HRESULT_FROM_WIN32(DWORD x);
Don't go down this road, and just define your own.
Reuse of the codes themselves is pointless, since having your own codes is just one #define away.
Reuse of the error strings is not such a good idea either:
These will be localized. So if your (English) application runs on a Chinese version of Windows, the user will see a mixture of the two languages.
Microsoft might change the text at their whim, with a new release of Windows or with an update. For example, if you used ERROR_IPSEC_IKE_INVALID_CERT_TYPE to indicate HTTPS certificate errors, and Microsoft decided to fix their vague message to say "Invalid IPSEC IKE certificate type" instead? (I don't know what IKE is at all, and have only a vague notion about IPSEC, but you get the point.)
You'll have no way of customizing the error messages to be clearer or more specific.
Once users of your API start using FormatMessage, you'll be forever tied to the set of error codes and messages that Microsoft provides.
If you already know that Raymond Chen would slap you, why are you even considering this? ;)
i think i may have found my own answer, by actually reading the documentation:
System Error Codes
The System Error Codes are very broad. ... Because these codes are defined in WinError.h for anyone to use, sometimes the codes are returned by non-system software.
Although only error codes are described as such (i.e. positive numbers from 0-15999).
But the same spirit starts to apply to COM error codes:
E_NOTIMPL: 0x80004001 Not implemented
E_INVALIDARG: 0x80070057 One or more arguments are invalid
E_FAIL: 0x80004005 Unspecified error (The dreaded 80004005 unspecified error, error)
In fact it's Delphi's safecall mapping that converts any generic exception into
E_UNEXPECTED 0x8000FFFF Catastrophic failure
So it's quite expected to use Microsoft's HRESULT codes.
You also have the HRESULTs that are HRESULT formulations of the standard Win32 error codes, e.g. E_HANDLE is a wrapper around ERROR_INVALID_HANDLE (6):
E_HANDLE = 0x80070006; //Invalid handle
Which is done using the HRESULT_FROM_WIN32 macro.
Although it might be morally questionable to use Microsoft HRESULTS outside generic facilities:
FACILITY_NULL For broadly applicable common status codes such as S_OK.
FACILITY_RPC For status codes returned from remote procedure calls.
FACILITY_DISPATCH For late-binding IDispatch interface errors.
FACILITY_ITF For most status codes returned from interface methods. The actual meaning of the error is defined by the interface. That is, two HRESULTs with exactly the same 32-bit value returned from two different interfaces might have different meanings.
FACILITY_WIN32 Used to provide a means of handling error codes from functions in the Windows API as an HRESULT.
CreateFile for example. When I get INVALID_HANDLE_VALUE, what are all the possible values that can be returned by GetLastError? MSDN doesn't say. It mentions some and I can guess others, but how (if at all) can I be sure that my switch statement will never reach default?
Such a list doesn't exist and in fact you can't ever have such a list. In some future version of Windows a function may well start returning an error code that did not exist when you compiled your program.
The standard way to deal with this is handle any error codes that you know about that need special treatment, and let all others fall through to a default handler. Call FormatMessage() to get a descriptive text string for the error.
Documentation for RunWait() lacks description of returned error codes.
What do the different error code values mean?
It is because these codes appear as a result of the programs you run with RunWait, not to this AutoIT function.
Generic success code is zero, and any non-zero value could mean absolutely anything, and the only way to know what happened is to study this exact app or console command output.