@@ -37,8 +37,8 @@ def GetModule(tlib):
37
37
"""Create a module wrapping a COM typelibrary on demand.
38
38
39
39
'tlib' must be an ITypeLib COM pointer instance, the pathname of a
40
- type library, or a tuple/list specifying the arguments to a
41
- comtypes.typeinfo.LoadRegTypeLib call:
40
+ type library, a COM CLSID GUID, or a tuple/list specifying the
41
+ arguments to a comtypes.typeinfo.LoadRegTypeLib call:
42
42
43
43
(libid, wMajorVerNum, wMinorVerNum, lcid=0)
44
44
@@ -93,6 +93,19 @@ def GetModule(tlib):
93
93
logger .debug ("GetModule(%s)" , tlib )
94
94
pathname = tlib
95
95
tlib = comtypes .typeinfo .LoadTypeLibEx (tlib )
96
+ elif isinstance (tlib , comtypes .GUID ):
97
+ # tlib contain a clsid
98
+ clsid = str (tlib )
99
+
100
+ # lookup associated typelib in registry
101
+ import _winreg
102
+ with _winreg .OpenKey (_winreg .HKEY_CLASSES_ROOT , r"CLSID\%s\TypeLib" % clsid , 0 , _winreg .KEY_READ ) as key :
103
+ typelib = _winreg .EnumValue (key , 0 )[1 ]
104
+ with _winreg .OpenKey (_winreg .HKEY_CLASSES_ROOT , r"CLSID\%s\Version" % clsid , 0 , _winreg .KEY_READ ) as key :
105
+ version = _winreg .EnumValue (key , 0 )[1 ].split ("." )
106
+
107
+ logger .debug ("GetModule(%s)" , typelib )
108
+ tlib = comtypes .typeinfo .LoadRegTypeLib (comtypes .GUID (typelib ), int (version [0 ]), int (version [1 ]), 0 )
96
109
elif isinstance (tlib , (tuple , list )):
97
110
# sequence containing libid and version numbers
98
111
logger .debug ("GetModule(%s)" , (tlib ,))
0 commit comments