How to get detail error info from E_FAIL?
-
When I use ATL in MFC Application(Don't ask me why, just because I like), sometimes I got the error code: E_FAIL. However, it's almost useless for me to locate the specific reason. I have googled so many times, but found nothing related. I thought there should be something like try{} catch{} in ATL. Here's some sample code:
CAxWindow m_wndView; // ActiveX host window class.
CComPtr m_spWMPPlayer; // Smart pointer to IWMPPlayer interface.AtlAxWinInit();
CComPtr spHost;
HRESULT hr;
CRect rcClient;
GetClientRect(&rcClient);
m_wndView.Create(m_hWnd, rcClient, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
//when I switch to Static Link to ATL from Dynamic Link to ATL, I always get E_FAIL
hr = m_wndView.QueryHost(&spHost); -
When I use ATL in MFC Application(Don't ask me why, just because I like), sometimes I got the error code: E_FAIL. However, it's almost useless for me to locate the specific reason. I have googled so many times, but found nothing related. I thought there should be something like try{} catch{} in ATL. Here's some sample code:
CAxWindow m_wndView; // ActiveX host window class.
CComPtr m_spWMPPlayer; // Smart pointer to IWMPPlayer interface.AtlAxWinInit();
CComPtr spHost;
HRESULT hr;
CRect rcClient;
GetClientRect(&rcClient);
m_wndView.Create(m_hWnd, rcClient, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
//when I switch to Static Link to ATL from Dynamic Link to ATL, I always get E_FAIL
hr = m_wndView.QueryHost(&spHost);Use the
_com_error
class. Construct an object of this class by passing in theHRESULT
value and then use itsWCode
orErrorMessage
methods to get the error code mapped to theHRESULT
value.«_Superman_» _I love work. It gives me something to do between weekends.
-
Use the
_com_error
class. Construct an object of this class by passing in theHRESULT
value and then use itsWCode
orErrorMessage
methods to get the error code mapped to theHRESULT
value.«_Superman_» _I love work. It gives me something to do between weekends.
Thank you for your reply. I have did as what you said, but I only get the error message: Unspecified error. Here is my code:
_com_error err(hr);
auto d = err.WCode();
auto s = err.Description();
auto msg = err.ErrorMessage();//Unspecified error -
Thank you for your reply. I have did as what you said, but I only get the error message: Unspecified error. Here is my code:
_com_error err(hr);
auto d = err.WCode();
auto s = err.Description();
auto msg = err.ErrorMessage();//Unspecified error'Unspecified error' is the english error message for
E_FAIL
. There is no more information available. -
When I use ATL in MFC Application(Don't ask me why, just because I like), sometimes I got the error code: E_FAIL. However, it's almost useless for me to locate the specific reason. I have googled so many times, but found nothing related. I thought there should be something like try{} catch{} in ATL. Here's some sample code:
CAxWindow m_wndView; // ActiveX host window class.
CComPtr m_spWMPPlayer; // Smart pointer to IWMPPlayer interface.AtlAxWinInit();
CComPtr spHost;
HRESULT hr;
CRect rcClient;
GetClientRect(&rcClient);
m_wndView.Create(m_hWnd, rcClient, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
//when I switch to Static Link to ATL from Dynamic Link to ATL, I always get E_FAIL
hr = m_wndView.QueryHost(&spHost);You can try with GetLastError and see if you can get better description of the error . The number returned from the function you can check in msdn. Good luck :)