0

I am developing a program using the HIDAPI for USB communications and it appears that the API function hid_error() returns the last error message direct from windows, not a message generated by the API itself. Where can I find a list of all possible error messages so I can react more precisely to an error?

László Papp
  • 51,870
  • 39
  • 111
  • 135
Michel Feinstein
  • 13,416
  • 16
  • 91
  • 173
  • Common ones are declared in the WinError.h and NtStatus.h SDK headers. A driver can add its own. – Hans Passant Dec 28 '13 at 11:39
  • @HansPassant: in addition, the first google result is the relevant MSDN documentation. – László Papp Jan 01 '14 at 15:11
  • in addition StackOverflow is a place were questions get indexed and google produces better results thanks to questions in here and people with the same question get their answer more quickly....google: "windows error messages HID" and see the second result...anyone developing for HID that wants the error messages has a good and straight foward answer now. – Michel Feinstein Jan 01 '14 at 15:16
  • besides google results changes from every google user...when I search "windows error messages" I dont get the answer as a result...I get websites related to windows installation errors.... – Michel Feinstein Jan 01 '14 at 15:19

2 Answers2

2

I believe you are looking for the following two functions below in addition to the regular error codes on Windows, the documentation of which seems to be the first result on Google.

The first function will allow you to check the error code against the system error codes, and based on your desire (although you have not shared why you need any customization), you can either have a custom error message displayed, or you can just use the second function for keeping that when that is feasible. Surely, you could also keep the hid_error output since that is equivalent.

1) Getting the error code itself.

GetLastError function

Retrieves the calling thread's last-error code value. The last-error code is maintained on a per-thread basis. Multiple threads do not overwrite each other's last-error code.

2) Getting the string out of the error code.

FormatMessage function

Formats a message string. The function requires a message definition as input. The message definition can come from a buffer passed into the function. It can come from a message table resource in an already-loaded module. Or the caller can ask the function to search the system's message table resource(s) for the message definition. The function finds the message definition in a message table resource based on a message identifier and a language identifier. The function copies the formatted message text to an output buffer, processing any embedded insert sequences if requested.

In a Qt application for instance, this would be even a more natural way of handling the issue for your customization:

QString QtWin::errorStringFromHresult(HRESULT hresult)

Returns the code name of the hresult error id specified (usually the name of the WinAPI macro) or an empty string if the message is unknown.

László Papp
  • 51,870
  • 39
  • 111
  • 135
  • I am not asking how to get the last error. I am asking how to get a list of all possible errors so I can make my program react to all possible messages, depending on their content. – Michel Feinstein Dec 31 '13 at 03:53
  • @mFeinstein: have you actually read the answer? The answer is mentioning that how you can customize the error handling when necessary and how to have a fallback when that is not necessary. It provides the relevant API documentation inline as well as links for details. I am confused what your problem is. – László Papp Dec 31 '13 at 03:59
  • I did read it, but you edited it now, so it includes a whole new paragraph with "http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381%28v=vs.85%29.aspx" which WASNT there before. ALSO, if you read the HIDAPI hid_error() (that I posted) you will see that this function already calls functions 1 and 2 that you posted. And what do you mean by my desire wasnt posted?! I said I want to get the errors for analysis before coding so I can interpret all errors returned by hid_error() – Michel Feinstein Dec 31 '13 at 04:04
  • Seriouslly every post I make you just come to help in almost nothing and complain about everything, please do me a favor and stop commenting and answering my questions. You just make them HUGE and people avoid reading and helping. – Michel Feinstein Dec 31 '13 at 04:07
  • And now you edited your first comment, removing the offensive parts you directed to me...clever... – Michel Feinstein Dec 31 '13 at 04:26
  • @mFeinstein: I am still not sure why this post is having a -1 from you. As others noted to you in other threads, it is the wrong way of encouraging people to help you in their free time. I would like to repeat that I do not care about the reputation, but if you have any ideas how to improve the post, please mention it, and I will consider it. – László Papp Jan 01 '14 at 14:08
  • I downvoted it because you expose functions to be called that are already called by `hid_error()` and your answer didnt add anything in comparison with the others that were posted before. My question was about getting the list of possible errors for documentation purposes, and you answered how to get erros in runtime and yes you edited it later and included the list...but the list was already posted by other users. – Michel Feinstein Jan 01 '14 at 14:37
  • @mFeinstein: hid_error() does **not** return a string/message which you were asking for. So, you upvote one user for the same correct information, and downvote the other? I would like to encourage you to stop this, otherwise you may be suspended if this continues. A lady got one year suspension for things like this: http://stackoverflow.com/users/1479606/eli The reason is basically that the site is to be objective rather than subjective. – László Papp Jan 01 '14 at 14:40
  • I downvoted you because it's not a new answer, just the same as Preston, and I think if someone will not post something new so it's just clutters and I think it went against the original question...and yes hid_error() returns a string, and yes I looked the code AND runned and the message returned was the same as the one in windows documentations. – Michel Feinstein Jan 01 '14 at 14:49
  • That is a typo, I meant error code. Anyway, it *is* a new answer because error codes are not enough on their own, you have to obtain the error codes somehow. hid_error definitely will not return that for you. Moreover, I even provided a Qt approach how to do it if someone reads this while programming a Qt application. – László Papp Jan 01 '14 at 14:52
  • besides the one who downvotes everyone all the time is you (as noted by other users)...so you should be careful about it too since you too can get suspended...oh wait, you cant :) – Michel Feinstein Jan 01 '14 at 14:53
  • please read hid_error() documentation...it returns a wchar_t*...and inside the code, it does exacly the function calls you pointed out – Michel Feinstein Jan 01 '14 at 14:54
  • besides, why did you downvoted my question? haha am I hearing "double standard"? – Michel Feinstein Jan 01 '14 at 14:58
  • http://www.signal11.us/oss/hidapi/hidapi/doxygen/html/group__API.html#ga1b5c0ca1c785b8024f5eb46750a8f606 – Michel Feinstein Jan 01 '14 at 15:01
  • wchar_t* **!=** error code. That is the error string! You were asking about handling different error codes different, and you got that! The downvote of my friend (not mine!) was done because "The msdn documentation is the first result on google". – László Papp Jan 01 '14 at 15:09
  • read my question, I never said "error codes" I said "error messages" – Michel Feinstein Jan 01 '14 at 15:12
  • Now I upvoted you because you made clear `hid_error()` returns the message, but you also give the option to get the error code, which is better in general. – Michel Feinstein Jan 01 '14 at 15:24
  • Ok, I thought it will be nice to select the first one, like for his merit, but I didnt knew about the help center....sorry @Preston and thanks a lot! – Michel Feinstein Jan 02 '14 at 06:31
1

You might have a look at the System Error Codes.

Preston
  • 2,543
  • 1
  • 17
  • 26