From f2a287d818e524297b2d52078a65f4cdfe0dc67d Mon Sep 17 00:00:00 2001 From: hakril Date: Wed, 8 Jan 2025 19:31:28 +0100 Subject: [PATCH] Add some ctypes generation + HRESULT_FACILITY macro --- .../definitions/defines/error_helper.txt | 20 ++++++++++++++++++- .../definitions/defines/template.py | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ctypes_generation/definitions/defines/error_helper.txt b/ctypes_generation/definitions/defines/error_helper.txt index 99a693e..64f9c51 100644 --- a/ctypes_generation/definitions/defines/error_helper.txt +++ b/ctypes_generation/definitions/defines/error_helper.txt @@ -2,4 +2,22 @@ #define ERROR_SEVERITY_SUCCESS 0x00000000 #define ERROR_SEVERITY_INFORMATIONAL 0x40000000 #define ERROR_SEVERITY_WARNING 0x80000000 -#define ERROR_SEVERITY_ERROR 0xC0000000 \ No newline at end of file +#define ERROR_SEVERITY_ERROR 0xC0000000 + +// https://learn.microsoft.com/en-us/windows/win32/com/structure-of-com-error-codes +// Define the facility codes +// +#define FACILITY_WINDOWS 0x8 +#define FACILITY_WIN32 0x7 +#define FACILITY_STORAGE 0x3 +#define FACILITY_RPC 0x1 +#define FACILITY_NULL 0x0 +#define FACILITY_ITF 0x4 +#define FACILITY_DISPATCH 0x2 + + +// +// Define the severity codes +// +#define STATUS_SEVERITY_SUCCESS 0x0 +#define STATUS_SEVERITY_COERROR 0x2 \ No newline at end of file diff --git a/ctypes_generation/definitions/defines/template.py b/ctypes_generation/definitions/defines/template.py index b95b199..182bddf 100644 --- a/ctypes_generation/definitions/defines/template.py +++ b/ctypes_generation/definitions/defines/template.py @@ -17,3 +17,10 @@ NATIVE_WORD_MAX_VALUE = 0xffffffff if bitness == 32 else 0xffffffffffffffff def CTL_CODE(DeviceType, Function, Method, Access): return (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)) + +# https://learn.microsoft.com/en-us/windows/win32/api/winerror/nf-winerror-hresult_facility +# Original MACRO: +# #define HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff) + +def HRESULT_FACILITY(hr): + return (((hr) >> 16) & 0x1fff)