You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
New users of this package may find themselves deeply confused when encountering a COMError.
COMError is an exception defined in the ctypes internal implementation, _ctypes, and is part of the Python standard library. However, it remained undocumented for many years. To address this, I opened an issue and submitted a pull request to add documentation for this error to the official Python documentation.
Another problem with COMError is that most COM references typically represent error codes as signed 32-bit hexadecimal values, like the ones below, while the error code assigned to its hresult attribute is an int, making them less 'googlable'.
Additionally, converting between signed 32-bit hexadecimal strings and integer values requires some extra effort.
For instance, when I was less familiar with HRESULT, I mistakenly tried to derive the integer value for E_NOINTERFACE using int("0x80004002", 16).
To handle these conversions properly, a utility function like the following is necessary:
For example, let’s consider the case where you encounter an COMError: (-2146233083, ..., ...).
Searching for -2146233083 alone will primarily return information about COR_E_TIMEOUT, which is related to .NET.
However, searching for "0x80131505", which can be derived using int_to_signed32bithex(-2146233083), makes it easier to find information about UIA_E_TIMEOUT, which is related to UIAutomation.
I am considering adding such a function to comtypes/hresult.py with appropriate docstrings.
Doing so will likely reduce the number of inquiries related to error handling in the future, preventing burnout among the community and maintainers.
The text was updated successfully, but these errors were encountered:
New users of this package may find themselves deeply confused when encountering a
COMError
.COMError
is an exception defined in thectypes
internal implementation,_ctypes
, and is part of the Python standard library. However, it remained undocumented for many years. To address this, I opened an issue and submitted a pull request to add documentation for this error to the official Python documentation.Another problem with
COMError
is that most COM references typically represent error codes as signed 32-bit hexadecimal values, like the ones below, while the error code assigned to itshresult
attribute is anint
, making them less 'googlable'.Additionally, converting between signed 32-bit hexadecimal strings and integer values requires some extra effort.
For instance, when I was less familiar with HRESULT, I mistakenly tried to derive the integer value for
E_NOINTERFACE
usingint("0x80004002", 16)
.To handle these conversions properly, a utility function like the following is necessary:
For example, let’s consider the case where you encounter an
COMError: (-2146233083, ..., ...)
.Searching for
-2146233083
alone will primarily return information aboutCOR_E_TIMEOUT
, which is related to .NET.However, searching for
"0x80131505"
, which can be derived usingint_to_signed32bithex(-2146233083)
, makes it easier to find information aboutUIA_E_TIMEOUT
, which is related to UIAutomation.I am considering adding such a function to
comtypes/hresult.py
with appropriate docstrings.Doing so will likely reduce the number of inquiries related to error handling in the future, preventing burnout among the community and maintainers.
The text was updated successfully, but these errors were encountered: