如何从HRESULT中获取错误代码 [英] How to get an error code out of an HRESULT

查看:305
本文介绍了如何从HRESULT中获取错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我所拥有的:

This is what I have:

CComQIPtr<ICSFTHST>	spHst;

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



有时hr1是成功,有时是失败!

我一直在尝试各种方法来从hr1中获取错误代码,现在已经有好几天了,我感到非常沮丧.

如何从hr1中获取错误代码?请帮忙!



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!

推荐答案

Raymond Chen曾就此发表过博客:

参见 http://blogs.msdn.com/b/oldnewthing/archive/2006 /11/03/942851.aspx [ ^ ]
Raymond Chen has blogged about this:

See http://blogs.msdn.com/b/oldnewthing/archive/2006/11/03/942851.aspx[^]


阅读^ ]关于HRESULT.

您可能可以使用 FormatMessage [ CoCreateInstance [ ^ ]
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[^]


已经炒过了,但是运气还不高!!

* pdwWin32 = HRESULT_CODE(hr);

尝试了一切,终于有很大帮助!

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

但我想知道上面的声明总是返回操作成功完成"

可能-com-error与Andrew所说的有所不同,因为根据安德鲁(Andrew)给出的链接,

或者,您可以仅使用MSDN文档检查CoCreateInstance的返回值[^]

S_OK显示了不同的描述.
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.


这篇关于如何从HRESULT中获取错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆