2017-10-06 37 views
0

class SharpDXException有一個字段int HResult,當底層Microsoft DirectX代碼報告錯誤時,該字段設置爲非零錯誤代碼。SharpDX是否有一個枚舉給DirectDD錯誤代碼提供常量名稱,這些代碼可以在SharpDXException中返回?

例如,當使用SharpDX.Direct2D1時,Microsoft docs list these Direct2D error codes

例如,

D2DERR_RECREATE_TARGET
0x8899000C

搜索SharpDX來源,我沒有看到它 「重建」 任何東西。

我希望有一些錯誤枚舉是自動生成的,因此不在源中。因此可以輸入類似SharpDX.Direct2D1.D2DERR.RECREATE_TARGET的內容來引用該錯誤代碼。
(我一直在試圖對不同的變化,沒有找到通過智能感知枚舉。)


如果不存在,有沒有人發佈包含這些錯誤代碼的C#文件?

(A C++代碼的版本是在d2derr.h 例如:

https://github.com/depletionmode/d2d1headers/blob/master/d2derr.h

回答

0

基於

https://github.com/depletionmode/d2d1headers/blob/master/d2derr.h

使用

https://www.tangiblesoftwaresolutions.com/free_editions.html
「安裝C++到C#轉換」

在C#(有一些手動編輯):

// Similar to d2derr.h - Header file for the Direct2D API. 
// No original Microsoft headers were used in the creation of this file. 

internal static class D2DERR 
{ 
    public const uint BAD_NUMBER = 0x88990011; 
    public const uint DISPLAY_FORMAT_NOT_SUPPORTED = 0x88990009; 
    public const uint DISPLAY_STATE_INVALID = 0x88990006; 
    public const uint EXCEEDS_MAX_BITMAP_SIZE = 0x8899001D; 
    public const uint INCOMPATIBLE_BRUSH_TYPES = 0x88990018; 
    public const uint INTERNAL_ERROR = 0x88990008; 
    public const uint INVALID_CALL = 0x8899000A; 
    public const uint LAYER_ALREADY_IN_USE = 0x88990013; 
    public const uint MAX_TEXTURE_SIZE_EXCEEDED = 0x8899000F; 
    public const uint NO_HARDWARE_DEVICE = 0x8899000B; 
    public const uint NOT_INITIALIZED = 0x88990002; 
    public const uint POP_CALL_DID_NOT_MATCH_PUSH = 0x88990014; 
    public const uint PUSH_POP_UNBALANCED = 0x88990016; 
    public const uint RECREATE_TARGET = 0x8899000C; 
    public const uint RENDER_TARGET_HAS_LAYER_OR_CLIPRECT = 0x88990017; 
    public const uint SCANNER_FAILED = 0x88990004; 
    public const uint SCREEN_ACCESS_DENIED = 0x88990005; 
    public const uint SHADER_COMPILE_FAILED = 0x8899000E; 
    public const uint TARGET_NOT_GDI_COMPATIBLE = 0x8899001A; 
    public const uint TEXT_EFFECT_IS_WRONG_TYPE = 0x8899001B; 
    public const uint TEXT_RENDERER_NOT_RELEASED = 0x8899001C; 
    public const uint TOO_MANY_SHADER_ELEMENTS = 0x8899000D; 
    public const uint UNSUPPORTED_OPERATION = 0x88990003; 
    public const uint UNSUPPORTED_VERSION = 0x88990010; 
    public const uint WIN32_ERROR = 0x88990019; 
    public const uint WRONG_FACTORY = 0x88990012; 
    public const uint WRONG_RESOURCE_DOMAIN = 0x88990015; 
    public const uint WRONG_STATE = 0x88990001; 
    public const uint ZERO_VECTOR = 0x88990007; 
} 

然後,使用

http://converter.telerik.com/

在VB:

' Similar to d2derr.h - Header file for the Direct2D API. 
' No original Microsoft headers were used in the creation of this file. 

Friend NotInheritable Class D2DERR 
    Private Sub New() 
    End Sub 
    Public Const BAD_NUMBER As UInteger = &H88990011UI 
    Public Const DISPLAY_FORMAT_NOT_SUPPORTED As UInteger = &H88990009UI 
    Public Const DISPLAY_STATE_INVALID As UInteger = &H88990006UI 
    Public Const EXCEEDS_MAX_BITMAP_SIZE As UInteger = &H8899001dUI 
    Public Const INCOMPATIBLE_BRUSH_TYPES As UInteger = &H88990018UI 
    Public Const INTERNAL_ERROR As UInteger = &H88990008UI 
    Public Const INVALID_CALL As UInteger = &H8899000aUI 
    Public Const LAYER_ALREADY_IN_USE As UInteger = &H88990013UI 
    Public Const MAX_TEXTURE_SIZE_EXCEEDED As UInteger = &H8899000fUI 
    Public Const NO_HARDWARE_DEVICE As UInteger = &H8899000bUI 
    Public Const NOT_INITIALIZED As UInteger = &H88990002UI 
    Public Const POP_CALL_DID_NOT_MATCH_PUSH As UInteger = &H88990014UI 
    Public Const PUSH_POP_UNBALANCED As UInteger = &H88990016UI 
    Public Const RECREATE_TARGET As UInteger = &H8899000cUI 
    Public Const RENDER_TARGET_HAS_LAYER_OR_CLIPRECT As UInteger = &H88990017UI 
    Public Const SCANNER_FAILED As UInteger = &H88990004UI 
    Public Const SCREEN_ACCESS_DENIED As UInteger = &H88990005UI 
    Public Const SHADER_COMPILE_FAILED As UInteger = &H8899000eUI 
    Public Const TARGET_NOT_GDI_COMPATIBLE As UInteger = &H8899001aUI 
    Public Const TEXT_EFFECT_IS_WRONG_TYPE As UInteger = &H8899001bUI 
    Public Const TEXT_RENDERER_NOT_RELEASED As UInteger = &H8899001cUI 
    Public Const TOO_MANY_SHADER_ELEMENTS As UInteger = &H8899000dUI 
    Public Const UNSUPPORTED_OPERATION As UInteger = &H88990003UI 
    Public Const UNSUPPORTED_VERSION As UInteger = &H88990010UI 
    Public Const WIN32_ERROR As UInteger = &H88990019UI 
    Public Const WRONG_FACTORY As UInteger = &H88990012UI 
    Public Const WRONG_RESOURCE_DOMAIN As UInteger = &H88990015UI 
    Public Const WRONG_STATE As UInteger = &H88990001UI 
    Public Const ZERO_VECTOR As UInteger = &H88990007UI 
End Class 

例C#用法:

try { 
    renderTarget.EndDraw(); 
} catch (SharpDXException ex) { 
    if (ex.HResult == D2DERR.RECREATE_TARGET) 
     ... 
} 
相關問題