factory.py 766 B

12345678910111213141516171819202122
  1. # Class factory utilities.
  2. import pythoncom
  3. def RegisterClassFactories(clsids, flags = None, clsctx = None):
  4. """Given a list of CLSID, create and register class factories.
  5. Returns a list, which should be passed to RevokeClassFactories
  6. """
  7. if flags is None: flags = pythoncom.REGCLS_MULTIPLEUSE|pythoncom.REGCLS_SUSPENDED
  8. if clsctx is None: clsctx = pythoncom.CLSCTX_LOCAL_SERVER
  9. ret = []
  10. for clsid in clsids:
  11. # Some server append '-Embedding' etc
  12. if clsid[0] not in ['-', '/']:
  13. factory = pythoncom.MakePyFactory(clsid)
  14. regId = pythoncom.CoRegisterClassObject(clsid, factory, clsctx, flags)
  15. ret.append((factory, regId))
  16. return ret
  17. def RevokeClassFactories(infos):
  18. for factory, revokeId in infos:
  19. pythoncom.CoRevokeClassObject(revokeId)