將微軟舊版託管DirectX接口的代碼移植到SharpDX上。SharpDX.Direct2D1.RenderTarget.EndDraw不返回HRESULT - 如何檢測失敗?特別是D2DERR_RECREATE_TARGET?
爲Microsoft's ID2D1RenderTarget::EndDraw的文件說,它應該返回一個HRESULT
:
如果該方法成功,則返回S_OK。否則,它將返回HRESULT錯誤代碼,並將tag1和tag2設置爲發生錯誤時處於活動狀態的標籤。
特別重要的是,這是我通常會檢測到需要重新創建目標的地方(D2DERR_RECREATE_TARGET
)。事實上,微軟在他們的例子中顯示了這一點:
hr = m_pRenderTarget->EndDraw();
if (hr == D2DERR_RECREATE_TARGET) ...
SharpDX的實現是一個子例程 - 沒有返回值。可以看出在github source:
/// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code and sets tag1 and tag2 to the tags that were active when the error occurred. </returns>
public void EndDraw()
的評論還提到了HRESULT,但是這是void
-returning。
如何查看HRESULT?