Skip to content

Commit bd1ed82

Browse files
authored
Fix TYPE_E_ELEMENTNOTFOUND HRESULT constant value. (#883)
* Fix incorrect HRESULT constant value for `TYPE_E_ELEMENTNOTFOUND`. The constant for `TYPE_E_ELEMENTNOTFOUND` was defined with an incorrect integer value, which did not correspond to the official HRESULT `0x8002802B`. This change corrects the value to `-2147319765`. * test: Verify HRESULT for GetTypeInfoOfGuid with null GUID. Assert that calling `ITypeLib::GetTypeInfoOfGuid` with a null GUID raises a `COMError` with the specific HRESULT `TYPE_E_ELEMENTNOTFOUND`. * Refactor: Use `IID_IFile` constant in `test_typeinfo.py`. In `comtypes/test/test_typeinfo.py`, the hardcoded GUID for `IFile` was replaced with the `IID_IFile` constant to improve readability.
1 parent b422668 commit bd1ed82

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

comtypes/hresult.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
CONNECT_E_ADVISELIMIT = -2147220991
2828
CONNECT_E_NOCONNECTION = -2147220992
2929

30-
TYPE_E_ELEMENTNOTFOUND = -2147352077 # 0x8002802BL
30+
TYPE_E_ELEMENTNOTFOUND = -2147319765 # 0x8002802B
3131

3232
TYPE_E_REGISTRYACCESS = -2147319780 # 0x8002801CL
3333
TYPE_E_CANTLOADLIBRARY = -2147312566 # 0x80029C4AL

comtypes/test/test_typeinfo.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import unittest
55
from ctypes.wintypes import MAX_PATH
66

7+
import comtypes.hresult
78
from comtypes import GUID, COMError
89
from comtypes.typeinfo import (
910
TKIND_DISPATCH,
@@ -84,16 +85,17 @@ def test_TypeInfo(self):
8485
ti.GetVarDesc(v)
8586

8687
guid_null = GUID()
87-
with self.assertRaises(COMError):
88+
with self.assertRaises(COMError) as cm:
8889
tlib.GetTypeInfoOfGuid(guid_null)
90+
self.assertEqual(comtypes.hresult.TYPE_E_ELEMENTNOTFOUND, cm.exception.hresult)
8991

90-
guid = GUID("{C7C3F5A4-88A3-11D0-ABCB-00A0C90FFFC0}")
91-
ti = tlib.GetTypeInfoOfGuid(guid)
92+
IID_IFile = GUID("{C7C3F5A4-88A3-11D0-ABCB-00A0C90FFFC0}")
93+
ti = tlib.GetTypeInfoOfGuid(IID_IFile)
9294
c_tlib, c_index = ti.GetContainingTypeLib()
9395
c_ti = c_tlib.GetTypeInfo(c_index)
9496
self.assert_tlibattr_equal(c_tlib, tlib)
9597
self.assertEqual(c_ti, ti)
96-
self.assertEqual(guid, ti.GetTypeAttr().guid)
98+
self.assertEqual(IID_IFile, ti.GetTypeAttr().guid)
9799

98100

99101
class Test_GetModuleFileName(unittest.TestCase):

0 commit comments

Comments
 (0)