Does SharpDX have an enum giving constant names to the Direct2D error codes that can be returned in a SharpDXException?

0

class SharpDXException has a field int HResult that is set to a non-zero error code when an error is reported by the underlying Microsoft DirectX code.

For example, when using SharpDX.Direct2D1, Microsoft docs list these Direct2D error codes.

For example,

D2DERR_RECREATE_TARGET
0x8899000C

Searching SharpDX sources, I don't see anything with "RECREATE" in it.

I am hoping that there is some error enum that is auto-generated, and therefore not in the sources. So could type something like SharpDX.Direct2D1.D2DERR.RECREATE_TARGET to refer to that error code.
(I've been trying different variations on that, without finding an enum via intellisense.)


If that does not exist, has anyone posted a C# file containing those error codes?

(A C++ version of the codes is in d2derr.h. For example:

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

)

sharpdx
asked on Stack Overflow Oct 6, 2017 by ToolmakerSteve • edited Oct 6, 2017 by ToolmakerSteve

1 Answer

0

Based on

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

Using

https://www.tangiblesoftwaresolutions.com/free_editions.html
"Install C++ to C# Converter"

In C# (with some manual editing):

//  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;
}

Then using

http://converter.telerik.com/

In 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

Example C# usage:

try {
    renderTarget.EndDraw();
} catch (SharpDXException ex) {
    if (ex.HResult == D2DERR.RECREATE_TARGET)
        ...
}
answered on Stack Overflow Oct 6, 2017 by ToolmakerSteve • edited Oct 6, 2017 by ToolmakerSteve

User contributions licensed under CC BY-SA 3.0