1

Topic: The description of an error from HRESULT

Kind time of days! A question: how on error status code (HRESULT) to receive a line with its description? Not when really there was an error, and simply having its full code in HRESULR (for example 0x800A0E7F is the full code for an error adErrStillExecuting) we Take for an example: 1. The interface::: _ConnectionPtr from msado15.dll 2. An error: adErrStillExecuting - "Cannot perform operation while executing" - the full code (HRESULT) (int/hex):-2146824577/0x800A0E7F - error status code HRESULT_CODE (HRESULT) (int/hex): 3711/0x0E7F I Know 2 variants: 1)//the Code No1 LPWSTR lpwSrc=NULL; LPWSTR lpwDescr=NULL; LPWSTR lpwErrMsg=NULL; HRESULT hr = (HRESULT) 0x800A0E7FL;//so too tried _HRESULT_TYPEDEF _ (0x800A0E7FL) _com_error err (hr); LPWSTR lpwSrc = (LPWSTR) err. Source (); - it is received NULL LPWSTR lpwDescr = (LPWSTR) err. Description (); - it is received NULL LPWSTR lpwErrMsg = (LPWSTR) err. ErrorMessage (); - We receive "Unknown error 0x800A0E7F"} 2)//the Code No2 LPWSTR lpwSrc=NULL; LPWSTR lpwDescr=NULL; LPWSTR lpwErrMsg=NULL; HRESULT hr = (HRESULT) 0x800A0E7FL;//so too tried _HRESULT_TYPEDEF _ (0x800A0E7FL) try {_com_issue_error (hr);} catch (_com_error &err) {LPWSTR lpwSrc = (LPWSTR) err. Source (); - it is received NULL LPWSTR lpwDescr = (LPWSTR) err. Description (); - it is received NULL LPWSTR lpwErrMsg = (LPWSTR) err. ErrorMessage (); - it is received "Unknown error 0x800A0E7F"}} If these variants of the code to use after really happened error Source () and Description () are filled, but ErrorMessage all the same returns "Unknown error 0x800A0E7F", but Description () returns a line with the error description://the Code No3 LPWSTR lpwSrc=NULL; LPWSTR lpwDescr=NULL; LPWSTR lpwErrMsg=NULL; HRESULT hr=S_OK; try {hr = pSQLConnection-> Close (); if (FAILED (hr)) _com_issue_error (hr);} catch (_com_error &err) {LPWSTR lpwSrc = (LPWSTR) err. Source (); - it is received "ADODB.Connection" LPWSTR lpwDescr = (LPWSTR) err. Description (); - it is received "it is not possible to fulfill operation during asynchronous performance." LPWSTR lpwErrMsg = (LPWSTR) err. ErrorMessage (); - it is received "Unknown error 0x800A0E7F"}} And Source () and Description () return values only if the exception is caused by a line hr = pSQLConnection-> Close () (for example, in case of an error adErrStillExecuting) and if a line if (FAILED (hr)) _com_issue_error (hr) that they = NULL (for example, in case of error E_INVALIDARG (0x80070057) "the Parameter is set incorrectly.") and still how to force to produce a line in the language necessary to me? In main () registered setlocale (LC_ALL, "Russian"); Apparently in the code No3 Description () deduces in Russian, and ErrorMessage () in English. Help already all dug over.

2

Re: The description of an error from HRESULT

Hello, MASReady, you wrote: MAS> as on error status code (HRESULT) to receive a line with its description? Imho, generally in any way. For special cases in kernel32.dll is message table in which correspondences between Win32 error code/HResult and their string representations are resulted. In manual to process the table not so conveniently, therefore careful developers Windows invented function FormatMessage. For what that of other special cases in others dll there can be similar tables. For example, in wininet.dll is.

3

Re: The description of an error from HRESULT

Hello, Aniskin, you wrote: A> Hello, MASReady, you wrote: MAS>> as on error status code (HRESULT) to receive a line with its description? A> Imho, generally in any way. Why? On mine there was any concept, with the general codes of errors in HRESULT. Here for example.

4

Re: The description of an error from HRESULT

Hello, Carc, you wrote: MAS>>> as on error status code (HRESULT) to receive a line with its description? A>> Imho, generally in any way. A C> Why? On mine there was any concept, with the general codes of errors in HRESULT. Here for example. As I understood, the hardware has a task to receive the system text description of an error in language of system on the basis of error status code. I correctly understand, what you suggest to process pens all possible variants HRESULT in a construction case?

5

Re: The description of an error from HRESULT

Hello, MASReady, you wrote: MAS> the Question: how on error status code (HRESULT) to receive a line with its description? MAS> not when really there was an error, and simply having its full code in HRESULR (for example 0x800A0E7F is the full code for an error adErrStillExecuting) MAS>... MAS> And still how to force to produce a line in the language necessary to me? MAS> in main () registered setlocale (LC_ALL, "Russian"); MAS> Apparently in the code No3 Description () deduces in Russian, and ErrorMessage () in English. MAS> help already all dug over. Look at implementation _com_error:: ErrorMessage (), at once all becomes clear and even there will be a possibility to put a creative hand. Standardly the CATFISH informs on the errors through reset of code HRESULT. The standard codes of errors on that and standard that it is possible to receive the text description from the system the CATFISH (see _com_error:: ErrorMessage ()). Then, in connection with the extension of the codes of errors, there was interface IErrorInfo (functions GetErrorInfo|SetErrorInfo framing it) which gives possibility to the server to give the description of the last error to the client in addition to code HRESULT. If the code generating an error, does not expose the description this description at you never will be, also there is no possibility to influence description language. It is all a server prerogative. Some servers give the possibilities for access to UI, but it is not standardized not so.

6

Re: The description of an error from HRESULT

Hello, Aniskin, you wrote: A> Hello, Carc, you wrote: MAS>>>> as on error status code (HRESULT) to receive a line with its description? A>>> Imho, generally in any way. A C>> Why? On mine there was any concept, with the general codes of errors in HRESULT. Here for example. A> As I understood, the hardware has a task to receive the system text description of an error in language of system on the basis of error status code. I correctly understand, what you suggest to process pens all possible variants HRESULT in a construction case? I about other. A thought direction. And further there a lot of interesting is, like IErrorInfo ... Simply it seems to me that at a topic-starter not absolutely general case. Quite specific interface, quite specific error.

7

Re: The description of an error from HRESULT

Hello, Carc, you wrote: a C> I about other. A thought direction. And further there a lot of interesting is, like IErrorInfo ... Simply it seems to me that at a topic-starter not absolutely general case. Quite specific interface, quite specific error. The hardware like was specific was sounded by a question: the Question: how on error status code (HRESULT) to receive a line with its description? Not when really there was an error, and simply having its full code in HRESULR

8

Re: The description of an error from HRESULT

Hello, Aniskin, you wrote: A> Hello, Carc, you wrote: a C>> I about other. A thought direction. And further there a lot of interesting is, like IErrorInfo ... Simply it seems to me that at a topic-starter not absolutely general case. Quite specific interface, quite specific error. A> the hardware like was specific was sounded by a question: A> the Question: how on error status code (HRESULT) to receive a line with its description? A> not when really there was an error, and simply having its full code in HRESULR so! When really there was an error, how I already wrote, in catch method Description () returns its description and how to receive the description simply having the full code HRESULT

9

Re: The description of an error from HRESULT

Hello, Aniskin, you wrote: A> Hello, MASReady, you wrote: MAS>> as on error status code (HRESULT) to receive a line with its description? A> Imho, generally in any way. For special cases in kernel32.dll is message table in which correspondences between Win32 error code/HResult and their string representations are resulted. In manual to process the table not so conveniently, therefore careful developers Windows invented function FormatMessage. For what that of other special cases in others dll there can be similar tables. For example, in wininet.dll is. FormatMessage I tried to attract - does not approach, it either sends, or returns descriptions of errors with the same code but from other tables of errors

10

Re: The description of an error from HRESULT

Hello, Vi2, you wrote: Vi2> Hello, MASReady, you wrote: MAS>> the Question: how on error status code (HRESULT) to receive a line with its description? MAS>> not when really there was an error, and simply having its full code in HRESULR (for example 0x800A0E7F is the full code for an error adErrStillExecuting) MAS>>... MAS>> And still how to force to produce a line in the language necessary to me? MAS>> in main () registered setlocale (LC_ALL, "Russian"); MAS>> Apparently in the code No3 Description () deduces in Russian, and ErrorMessage () in English. MAS>> help already all dug over. Vi2> look at implementation _com_error:: ErrorMessage (), at once all becomes clear and even there will be a possibility to put a creative hand. Vi2> standardly the CATFISH informs on the errors through reset of code HRESULT. The standard codes of errors on that and standard that it is possible to receive the text description from the system the CATFISH (see _com_error:: ErrorMessage ()). Vi2> Then, in connection with the extension of the codes of errors, there was interface IErrorInfo (functions GetErrorInfo|SetErrorInfo framing it) which gives possibility to the server to give the description of the last error to the client in addition to code HRESULT. If the code generating an error, does not expose the description this description at you never will be, also there is no possibility to influence description language. It is all a server prerogative. Vi2> some servers give the possibilities for access to UI, but it is not standardized not so. Why then, at real origin of error Description () returns its description, and ErrorMessage () returns a line in which writes, what this error does not know? The sense of all of it is approximately clear that the error description is only in a specific copy which this error produced and produced with it its description, but somehow it is all not so Is at interface Collection Errors about which it is much written and to which like as errors with descriptions and all other parameters, but at me never should get, any error there did not appear, how many I did not try

11

Re: The description of an error from HRESULT

Hello, MASReady, you wrote: MAS> and how to receive the description simply having the full code HRESULT In any way. The description is formed by the one who excites an exception. If I in the COM object write that that like raise ComException. Create (E_FAIL, ' very not clear error ') a line ' very not clear error ' will be accessible only in the output agent of an exception. Also is not present what possibility on value E_FAIL to receive this line.

12

Re: The description of an error from HRESULT

Hello, MASReady, you wrote: MAS> FormatMessage I tried to attract - does not approach, it either sends, or returns descriptions of errors with the same code but from other tables of errors For what HRESULT you tried? What description received? What description expected to receive?

13

Re: The description of an error from HRESULT

Hello, Aniskin, you wrote: A> Hello, MASReady, you wrote: MAS>> FormatMessage I tried to attract - does not approach, it either sends, or returns descriptions of errors with the same code but from other tables of errors A> For what HRESULT you tried? What description received? What description expected to receive? I wrote in the beginning: we Take for an example: 1. The interface::: _ConnectionPtr from msado15.dll 2. An error: adErrStillExecuting - "Cannot perform operation while executing" - the full code (HRESULT) (int/hex):-2146824577/0x800A0E7F - error status code HRESULT_CODE (HRESULT) (int/hex): 3711/0x0E7F here is how to me having the code 0x800A0E7F to receive a line "Cannot perform operation while executing" ("it is not possible to fulfill operation during asynchronous performance.")?

14

Re: The description of an error from HRESULT

Hello, MASReady, you wrote: MAS> Why then, at real origin of error Description () returns its description, and ErrorMessage () returns a line in which writes, what this error does not know? Because the description to this error lies in object IErrorInfo, returned by a database instead of with error status code 0x800A0E7F. To a method of this object addresses _com_error:: Description, and _com_error:: ErrorMessage addresses to system resources with 0x800A0E7F which is the user code: #define SEVERITY_ERROR 1 #define FACILITY_CONTROL 10 #define MAKE_HRESULT (sev, fac, code) \((HRESULT) (((unsigned long) (sev) <<31) | ((unsigned long) (fac) <<16) | ((unsigned long) (code)))) 0x800A0E7F == MAKE_HRESULT (SEVERITY_ERROR, FACILITY_CONTROL, 0xE7F/*ili 3711*/) MAS> the Sense of all of it is approximately clear that the error description is only in a specific copy which this error produced and produced with it its description, but somehow it is all not so MAS> Is at interface Collection Errors about which it is much written and to which like as errors with descriptions and all other parameters, but at me never should get, any error there did not appear, how many I did not try Therefore it is possible to save _com_error somewhere then to use its knowledge. Because object IErrorInfo will be replaced with another by a call of another the CATFISH of a method who changes it or should change by the operation. And can for saving and this is invented Collection Errors, only it is necessary most to push errors there.

15

Re: The description of an error from HRESULT

Hello, MASReady, you wrote: MAS> here is how to me having the code 0x800A0E7F to receive a line "Cannot perform operation while executing" ("it is not possible to fulfill operation during asynchronous performance." )? The line "is not possible to fulfill operation during asynchronous performance" contains in string based resources msader15.dll with the identifier 0x0E7F. Coincidence? I do not think. .jpg. Therefore for the errors beginning with 0x800A we read a line from msader15.dll, for remaining - by default. It is necessary to define only a correct location msader15.dll. In native  translate: function HResultToString (AErrorCode: HRESULT): string; const DefFlags: DWORD = FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS or FORMAT_MESSAGE_ARGUMENT_ARRAY or FORMAT_MESSAGE_ALLOCATE_BUFFER; var Buffer: PChar; BufferLen, Len: Integer; Module: HMODULE; begin Result: = ' very not clear error: 0x ' + IntToHex (AErrorCode, SizeOf (AErrorCode) * 2); case AErrorCode and $FFFF0000 of $800A0000: begin Module: = LoadLibrary (' c:\Program Files\Common Files\System\ado\msader15.dll '); if Module <> 0 then try AErrorCode: = AErrorCode and $0000FFFF; BufferLen: = 128; repeat BufferLen: = BufferLen * 2; SetLength (Result, BufferLen); Len: = LoadStringW (Module, AErrorCode, PWideChar (Result), BufferLen + 1); until Len <> BufferLen; SetLength (Result, Len); finally FreeLibrary (Module); end; end else begin Buffer: = nil; Len: = FormatMessage (DefFlags, nil, AErrorCode, 0, @Buffer, 0, nil); try if Len> 0 then begin Result: = Buffer; Len: = Length (Result); while (Len> 0) and (Result [Len] in [#10, #13, #0]) do Dec (Len); SetLength (Result, Len); end; finally if Buffer <> nil then LocalFree (HLOCAL (Buffer)); end; end; end; end;

16

Re: The description of an error from HRESULT

Hello, Aniskin, you wrote: A> the Hardware like was specific was sounded by a question: A> the Question: how on error status code (HRESULT) to receive a line with its description? A> not when really there was an error, and simply having its full code in HRESULR Yes, litter, I did not catch a question

17

Re: The description of an error from HRESULT

Hello, Aniskin, you wrote: A> Hello, MASReady, you wrote: MAS>> here is how to me having the code 0x800A0E7F to receive a line "Cannot perform operation while executing" ("it is not possible to fulfill operation during asynchronous performance." )? A> the line "is not possible to fulfill operation during asynchronous performance" contains in string based resources msader15.dll with the identifier 0x0E7F. Coincidence? I do not think. .jpg. Therefore for the errors beginning with 0x800A we read a line from msader15.dll, for remaining - by default. It is necessary to define only a correct location msader15.dll. In native  translate: A> function HResultToString (AErrorCode: HRESULT): string; A> const A> DefFlags: DWORD = A> FORMAT_MESSAGE_FROM_SYSTEM or A> FORMAT_MESSAGE_IGNORE_INSERTS or A> FORMAT_MESSAGE_ARGUMENT_ARRAY or A> FORMAT_MESSAGE_ALLOCATE_BUFFER; A> var A> Buffer: PChar; A> BufferLen, Len: Integer; A> Module: HMODULE; A> begin A> Result: = ' very not clear error: 0x ' + IntToHex (AErrorCode, SizeOf (AErrorCode) * 2); A> case AErrorCode and $FFFF0000 of A> $800A0000: A> begin A> Module: = LoadLibrary (' c:\Program Files\Common Files\System\ado\msader15.dll '); A> if Module <> 0 then A> try A> AErrorCode: = AErrorCode and $0000FFFF; A> BufferLen: = 128; A> repeat A> BufferLen: = BufferLen * 2; A> SetLength (Result, BufferLen); A> Len: = LoadStringW (Module, AErrorCode, PWideChar (Result), BufferLen + 1); A> until Len <> BufferLen; A> SetLength (Result, Len); A> finally A> FreeLibrary (Module); A> end; A> end A> else A> begin A> Buffer: = nil; A> Len: = FormatMessage (DefFlags, nil, AErrorCode, 0, @Buffer, 0, nil); A> try A> if Len> 0 then A> begin A> Result: = Buffer; A> Len: = Length (Result); A> while (Len> 0) and (Result [Len] in [#10, #13, #0]) do A> Dec (Len); A> SetLength (Result, Len); A> end; A> finally A> if Buffer <> nil then A> LocalFree (HLOCAL (Buffer)); A> end; A> end; A> end; A Thanks are finite, but it is a special case I already understood that it is necessary to catch a line Description and to drag it with itself upward to an output of the message or saving in a broad gull simply these are standard ADO errors, could what-thread make title in which at least standard for a long time rigidly certain to push, not to climb, to search

18

Re: The description of an error from HRESULT

Hello, Aniskin, you wrote: A> Hello, MASReady, you wrote: MAS>> here is how to me having the code 0x800A0E7F to receive a line "Cannot perform operation while executing" ("it is not possible to fulfill operation during asynchronous performance." )? A> the line "is not possible to fulfill operation during asynchronous performance" contains in string based resources msader15.dll with the identifier 0x0E7F. Coincidence? I do not think. .jpg. Therefore for the errors beginning with 0x800A we read a line from msader15.dll, for remaining - by default. It is necessary to define only a correct location msader15.dll. In native  translate: A> function HResultToString (AErrorCode: HRESULT): string; A> const A> DefFlags: DWORD = A> FORMAT_MESSAGE_FROM_SYSTEM or A> FORMAT_MESSAGE_IGNORE_INSERTS or A> FORMAT_MESSAGE_ARGUMENT_ARRAY or A> FORMAT_MESSAGE_ALLOCATE_BUFFER; A> var A> Buffer: PChar; A> BufferLen, Len: Integer; A> Module: HMODULE; A> begin A> Result: = ' very not clear error: 0x ' + IntToHex (AErrorCode, SizeOf (AErrorCode) * 2); A> case AErrorCode and $FFFF0000 of A> $800A0000: A> begin A> Module: = LoadLibrary (' c:\Program Files\Common Files\System\ado\msader15.dll '); A> if Module <> 0 then A> try A> AErrorCode: = AErrorCode and $0000FFFF; A> BufferLen: = 128; A> repeat A> BufferLen: = BufferLen * 2; A> SetLength (Result, BufferLen); A> Len: = LoadStringW (Module, AErrorCode, PWideChar (Result), BufferLen + 1); A> until Len <> BufferLen; A> SetLength (Result, Len); A> finally A> FreeLibrary (Module); A> end; A> end A> else A> begin A> Buffer: = nil; A> Len: = FormatMessage (DefFlags, nil, AErrorCode, 0, @Buffer, 0, nil); A> try A> if Len> 0 then A> begin A> Result: = Buffer; A> Len: = Length (Result); A> while (Len> 0) and (Result [Len] in [#10, #13, #0]) do A> Dec (Len); A> SetLength (Result, Len); A> end; A> finally A> if Buffer <> nil then A> LocalFree (HLOCAL (Buffer)); A> end; A> end; A> end; A =NULL) {free (p); p=NULL;};} #define MyLocalFree (p) if (p! =NULL) {LocalFree (p); p=NULL;} //the Size of the buffer in characters selected for messages. There should be <= STRSAFE_MAX_CCH #define MSG_MAX_SIZE 300//a Length of the buffer characters selected for messages. Should <= STRSAFE_MAX_LENGTH=STRSAFE_MAX_CCH-1 #define MSG_MAX_LEN MSG_MAX_SIZE-1//be selected the storage smoothed out in the zero #define CALLOC_MEM_MSG (LPWSTR) calloc (1, MSG_MAX_SIZE*sizeof (WCHAR))/*....*///function selects storage towards the line, therefore after a call if returned not NULL, after result usage is done to it free LPWSTR HResultToString (HRESULT hr) {int iErr=0; int iRes=0; LPWSTR lpwRes=NULL; if (HRESULT_FACILITY (hr) == FACILITY_CONTROL) {HMODULE hm = LoadLibraryEx (L "C: \\Program Files \\Common Files \\System \\ADO \\msader15.dll", NULL, LOAD_LIBRARY_AS_DATAFILE); if (hm! = 0) {lpwRes=CALLOC_MEM_MSG; iRes = LoadStringW (hm, HRESULT_CODE (hr), lpwRes, MSG_MAX_LEN); FreeLibrary (hm);} else {iErr=GetLastError (); lpwRes=SysErrorMessage (iErr);} ;} else {LPWSTR lpwBuffer=NULL; iRes = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, hr, MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPWSTR) &lpwBuffer, 0, NULL); if (iRes> 0) {lpwRes = _wcsdup (lpwBuffer);} MyLocalFree (lpwBuffer);}; if (iRes == 0) {lpwRes=CALLOC_MEM_MSG; StringCchPrintf (lpwRes, MSG_MAX_LEN, L "Unknown error: 0x%08lx", hr);} return lpwRes;}; truth FormatMessage can return the description for other error with the same code

19

Re: The description of an error from HRESULT

all many thanks! All my guesses proved to be true we Will pick further.