class SharpDXException
有一个字段int HResult
,当基础Microsoft DirectX代码报告错误时,该字段设置为非零错误代码。
例如,使用SharpDX.Direct2D1
时,Microsoft docs list these Direct2D error codes。
例如,
D2DERR_RECREATE_TARGET
0x8899000C
搜索SharpDX来源,我没有看到任何关于"重新开始"在它。
我希望有一些自动生成的错误枚举,因此不在源代码中。因此可以输入类似SharpDX.Direct2D1.D2DERR.RECREATE_TARGET
的内容来引用该错误代码
(我一直尝试不同的变体,没有通过intellisense找到枚举。)
如果不存在,是否有人发布了包含这些错误代码的C#文件?
(代码的C ++版本位于d2derr.h
。
例如:
https://github.com/depletionmode/d2d1headers/blob/master/d2derr.h
)
答案 0 :(得分:0)
基于
https://github.com/depletionmode/d2d1headers/blob/master/d2derr.h
使用
https://www.tangiblesoftwaresolutions.com/free_editions.html
“将C ++安装到C#Converter”
在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;
}
然后使用
在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)
...
}