Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HRESULT to text?

54 views
Skip to first unread message

Bonj

unread,
Dec 6, 2004, 11:23:08 AM12/6/04
to
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.

Igor Tandetnik

unread,
Dec 6, 2004, 11:35:13 AM12/6/04
to
"Bonj" <Bo...@discussions.microsoft.com> wrote in message
news:E69654F8-8630-4D15...@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


Victor Bazarov

unread,
Dec 6, 2004, 11:46:44 AM12/6/04
to
Igor Tandetnik wrote:
> "Bonj" <Bo...@discussions.microsoft.com> wrote in message
> news:E69654F8-8630-4D15...@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.

Bonj

unread,
Dec 6, 2004, 12:05:08 PM12/6/04
to
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?

Bonj

unread,
Dec 6, 2004, 12:07:06 PM12/6/04
to
> 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..)

Igor Tandetnik

unread,
Dec 6, 2004, 12:13:32 PM12/6/04
to
"Bonj" <Bo...@discussions.microsoft.com> wrote in message
news:48D04367-191D-4B2B...@microsoft.com

> 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.

> 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?

Bonj

unread,
Dec 6, 2004, 1:54:39 PM12/6/04
to

> 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.

>
> 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.


Arnaud Debaene

unread,
Dec 6, 2004, 4:59:21 PM12/6/04
to
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


Bonj

unread,
Dec 6, 2004, 6:04:03 PM12/6/04
to
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" <adeb...@club-internet.fr> wrote in message
news:%23VLNP79...@TK2MSFTNGP12.phx.gbl...

0 new messages