Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is what I have:

CComQIPtr<ICSFTHST>	spHst;

HRESULT hr1  = CoCreateInstance(
    CClsid::m_CSFTHST, NULL, CLSCTX_LOCAL_SERVER, IID_ICSFTHST, 
    (void **)&spHst);


Sometimes hr1 is success and sometimes it's failure!

I have been trying all ways to get the error code out of hr1, it's been days now, and I am so frustated.

How do I get the error code out of hr1? Please help!
Posted
Updated 1-Feb-11 4:59am
v2

Raymond Chen has blogged about this:

See http://blogs.msdn.com/b/oldnewthing/archive/2006/11/03/942851.aspx[^]
 
Share this answer
 
Comments
Henry Minute 1-Feb-11 11:08am    
Excellent link. + 5
Espen Harlinn 1-Feb-11 11:33am    
Well, that's a good link :)
Nish Nishant 1-Feb-11 11:35am    
Thank you, Espen and Henry.
Sergey Alexandrovich Kryukov 1-Feb-11 12:36pm    
Good, relevant, a 5.
--SA
Read the article on MSDN[^] about HRESULT.

You may be able to use FormatMessage[^] to get error text (see the remarks section).

Or you can just check the return value with the MSDN docs for CoCreateInstance[^]
 
Share this answer
 
Comments
Espen Harlinn 1-Feb-11 11:39am    
Good 5+
Sergey Alexandrovich Kryukov 1-Feb-11 12:36pm    
Correct, my 5.
--SA
Already ried this one, but not much luck!!

*pdwWin32 = HRESULT_CODE(hr);

Tried everything, finally this is helping a lot!!

CString sErrorMsg = _com_error(hr1).ErrorMessage();

But i wonder the above statement is always returning "Operation completed sucessfully"

May be -com-error is different from what Andrew said, because according to the link andrew gave

Or you can just check the return value with the MSDN docs for CoCreateInstance[^]

S_OK shows a different description.
 
Share this answer
 
Comments
amarasat 1-Feb-11 14:38pm    
Thanks a lot everyone, i have a question now!!

CComQIPtr<icsfthst> spHst;

HRESULT hr1 = CoCreateInstance(
CClsid::m_CSFTHST, NULL, CLSCTX_LOCAL_SERVER, IID_ICSFTHST,
(void **)&spHst);

Since the hr1 value is S_OK, Is there anyway i can check to see if the pointer &spHst is still valid:
like it is pointing to a valid location or not?

or can i put the value of the pointer into a CString and output it to a file:

spHst.p is the value, i have to check if this points to a valid location if not or so make a log of this value in a trace file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900