Board index » Visual Studio » HRESULT to text?

HRESULT to text?

Visual Studio85
Hi

Is there any chance anyone could tell me how to go from an HRESULT to text?

I am using ADO via COM, and am getting the following HRESULT when I try to

call _Connection_Open:



-2147467259



I am calling it with

#define TESTCONNECT _T("Provider=SQLOLEDB;Integrated Security=SSPI;Data

Source=(local)")

...

hr = _Connection_Open(cndb, TESTCONNECT, _T(""), _T(""), -1);



I would like to know how to fix this error which even already I am

suspecting to be due to the fact that TESTCONNECT is not BSTR, however, I

would like to know how to get from that HRESULT to a meaningful message, when

calling functions of the ADO library.

I am using the SDK not visual studio/ATL/MFC, so _com_issue_error and

anything else in <comutil.h>is out.


-
 

Re:HRESULT to text?

"Bonj" <Bonj@discussions.microsoft.com>wrote in message

Quote
Is there any chance anyone could tell me how to go from an HRESULT to

text?



For system-defined HRESULTs, use

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM). If you want to see it while

debugging, put a variable into the Watch window and type ",hr" (without

quotes) after the variable name. There's also Error Lookup tool under

Tools menu in the IDE.



Quote
I am using ADO via COM, and am getting the following HRESULT

when I try to call _Connection_Open:



-2147467259



That would be 0x80004005 E_FAIL "Unspecified error".

--

With best wishes,

Igor Tandetnik



With sufficient thrust, pigs fly just fine. However, this is not

necessarily a good idea. It is hard to be sure where they are going to

land, and it could be dangerous sitting under them as they fly

overhead. -- RFC 1925





-

Re:HRESULT to text?

Igor Tandetnik wrote:

Quote
"Bonj" <Bonj@discussions.microsoft.com>wrote in message

news:E69654F8-8630-4D15-95A3-33A0766C3751@microsoft.com

>[...]

>-2147467259





That would be 0x80004005 E_FAIL "Unspecified error".



Helpful, eh? :-) No, I don't mean your reply, I mean MS'

error codes.

-

Re:HRESULT to text?

OK

I see FormatMessage defined in the docs as

DWORD FormatMessage(

DWORD dwFlags,

LPCVOID lpSource,

DWORD dwMessageId,

DWORD dwLanguageId,

LPTSTR lpBuffer,

DWORD nSize,

va_list* Arguments

);

So I presumably pass FORMAT_MESSAGE_FROM SYSTEM as the first parameter, ...

and the address of my HRESULT as the second?



I can guess what lpBuffer and nSize are for...

What about dwMessageID, dwLanguageID and va_list?

Can I just pass NULL to these?







"Igor Tandetnik" wrote:



Quote
"Bonj" <Bonj@discussions.microsoft.com>wrote in message

news:E69654F8-8630-4D15-95A3-33A0766C3751@microsoft.com

>Is there any chance anyone could tell me how to go from an HRESULT to

>text?



For system-defined HRESULTs, use

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM). If you want to see it while

debugging, put a variable into the Watch window and type ",hr" (without

quotes) after the variable name. There's also Error Lookup tool under

Tools menu in the IDE.



>I am using ADO via COM, and am getting the following HRESULT

>when I try to call _Connection_Open:

>

>-2147467259



That would be 0x80004005 E_FAIL "Unspecified error".

--

With best wishes,

Igor Tandetnik



With sufficient thrust, pigs fly just fine. However, this is not

necessarily a good idea. It is hard to be sure where they are going to

land, and it could be dangerous sitting under them as they fly

overhead. -- RFC 1925







-

Re:HRESULT to text?

Quote
Helpful, eh? :-) No, I don't mean your reply, I mean MS'

error codes.





I know, good aren't they! :-)

My favourite is "Unknown catastrophic failure".

Or is it just "Catastrophic failure"?



(as if that would be a known unknown..)

-

Re:HRESULT to text?

"Bonj" <Bonj@discussions.microsoft.com>wrote in message

Quote
OK

I see FormatMessage defined in the docs as

DWORD FormatMessage(

DWORD dwFlags,

LPCVOID lpSource,

DWORD dwMessageId,

DWORD dwLanguageId,

LPTSTR lpBuffer,

DWORD nSize,

va_list* Arguments

);

So I presumably pass FORMAT_MESSAGE_FROM SYSTEM as the first

parameter, ... and the address of my HRESULT as the second?



Why don't you go just one step further and actually read the complete

docs page? Which part of this do you have difficulty understanding:



If neither of these flags is set in dwFlags, then lpSource is ignored.

dwMessageId - Message identifier for the requested message.



Quote
I can guess what lpBuffer and nSize are for...



Why do you feel the need to guess? Presumably, you are literate, so why

can't you just read the documentation in lieu of guesswork?

--

With best wishes,

Igor Tandetnik



With sufficient thrust, pigs fly just fine. However, this is not

necessarily a good idea. It is hard to be sure where they are going to

land, and it could be dangerous sitting under them as they fly

overhead. -- RFC 1925





-

Re:HRESULT to text?



Quote
Why don't you go just one step further and actually read the complete

docs page?



Well, I didn't want to get bogged down in things that were irrelevant, such

as language id.



Quote


If neither of these flags is set in dwFlags, then lpSource is ignored.

dwMessageId - Message identifier for the requested message.



Right, OK - so dwMessageID is the HRESULT...the only difficulty I had in

unerstanding that was that an HRESULT could be represented by an LPCVOID

*or* a DWORD, if one of the parameters was of type HRESULT, I would have

understood it instantly. Likewise, I would have got it if it had said "this

parameter can take a message code, such as an HRESULT". Sorry if I was a bit

slow.





-

Re:HRESULT to text?

Bonj wrote:

Quote
>Why don't you go just one step further and actually read the complete

>docs page?



Well, I didn't want to get bogged down in things that were

irrelevant, such as language id.



So, as you didn't want to get "booged down", you asked this newsgroup to do

all the "bogging down" for you, right?



Arnaud

MVP - VC





-

Re:HRESULT to text?

Well, no - I wouldn't wish "getting bogged down in language ids" on

anybody - it was just really that I didn't understand why the function

didn't take an HRESULT as one of its parameters - I thought that other

people who use it on a day-to-day basis would have already sifted out that

and be able to reply in seconds.

Sorry.



"Arnaud Debaene" <adebaene@club-internet.fr>wrote in message

Quote
Bonj wrote:

>>Why don't you go just one step further and actually read the complete

>>docs page?

>

>Well, I didn't want to get bogged down in things that were

>irrelevant, such as language id.



So, as you didn't want to get "booged down", you asked this newsgroup to

do all the "bogging down" for you, right?



Arnaud

MVP - VC









-