| 426 | |
| 427 | |
| 428 | class ITypeComp(IUnknown): |
| 429 | _iid_ = GUID("{00020403-0000-0000-C000-000000000046}") |
| 430 | |
| 431 | def Bind( |
| 432 | self, name: str, flags: int = 0, lHashVal: int = 0 |
| 433 | ) -> _UnionT[ |
| 434 | tuple[Literal["function"], "FUNCDESC"], |
| 435 | tuple[Literal["variable"], "VARDESC"], |
| 436 | tuple[Literal["type"], "ITypeComp"], |
| 437 | None, |
| 438 | ]: |
| 439 | """Bind to a name""" |
| 440 | bindptr = BINDPTR() |
| 441 | desckind = DESCKIND() |
| 442 | ti: ITypeInfo = POINTER(ITypeInfo)() # type: ignore |
| 443 | self.__com_Bind( # type: ignore |
| 444 | name, lHashVal, flags, byref(ti), byref(desckind), byref(bindptr) |
| 445 | ) |
| 446 | kind = desckind.value |
| 447 | if kind == DESCKIND_FUNCDESC: |
| 448 | fd = _deref_with_release(bindptr.lpfuncdesc, ti.ReleaseFuncDesc) |
| 449 | return "function", fd |
| 450 | elif kind == DESCKIND_VARDESC: |
| 451 | vd = _deref_with_release(bindptr.lpvardesc, ti.ReleaseVarDesc) |
| 452 | return "variable", vd |
| 453 | elif kind == DESCKIND_TYPECOMP: |
| 454 | return "type", bindptr.lptcomp |
| 455 | elif kind == DESCKIND_IMPLICITAPPOBJ: |
| 456 | # `DESCKIND_IMPLICITAPPOBJ` is rare; mainly for Office Application. |
| 457 | # It indicates a global application object (`TYPEFLAG_FAPPOBJECT`). |
| 458 | # Few other COM components use this highly specialized flag. |
| 459 | # Thus, this path is unlikely to be hit in common scenarios. |
| 460 | raise NotImplementedError |
| 461 | elif kind == DESCKIND_NONE: |
| 462 | raise NameError("Name %s not found" % name) |
| 463 | # `DESCKIND_MAX` is an end-of-enumeration marker, not a valid return |
| 464 | # from `ITypeComp::Bind` in COM. If returned, it implies a malformed |
| 465 | # type library. The current implementation implicitly returns `None`. |
| 466 | |
| 467 | def BindType(self, name: str, lHashVal: int = 0) -> tuple[ITypeInfo, "ITypeComp"]: |
| 468 | """Bind a type, and return both the typeinfo and typecomp for it.""" |
| 469 | ti = POINTER(ITypeInfo)() |
| 470 | tc = POINTER(ITypeComp)() |
| 471 | self.__com_BindType(name, lHashVal, byref(ti), byref(tc)) # type: ignore |
| 472 | return ti, tc # type: ignore |
| 473 | |
| 474 | |
| 475 | ################ |
nothing calls this directly
no test coverage detected
searching dependent graphs…