python类CoCreateInstance()的实例源码

create_link.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__( self ):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
        )
dump_link.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def DumpLink(fname):
    shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
    persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
    persistFile.Load(fname,STGM_READ)
    shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
    fname, findData = shellLink.GetPath(0)
    print "Filename:", fname, ", UNC=", shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0]
    print "Description:", shellLink.GetDescription()
    print "Working Directory:", shellLink.GetWorkingDirectory()
    print "Icon:", shellLink.GetIconLocation()
IUniformResourceLocator.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__( self ):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_InternetShortcut, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IUniformResourceLocator
        )
axsite.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def __init__(self, site, engine):
    self.eScript = self.eParse = self.eSafety = None
    if type(engine) == type(''):
      engine = pythoncom.CoCreateInstance(engine,
                                          None,
                                          pythoncom.CLSCTX_SERVER,
                                          pythoncom.IID_IUnknown)

    self.eScript = engine.QueryInterface(axscript.IID_IActiveScript)
    self.eParse = engine.QueryInterface(axscript.IID_IActiveScriptParse)
    self.eSafety = engine.QueryInterface(axscript.IID_IObjectSafety)

    self.eScript.SetScriptSite(site)
    self.eParse.InitNew()
testHost4Dbg.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def TestEngine():
  model = {'Test' : util.wrap(ObjectModel()) }
  scriptDir = "."
  site = MySite(model)
  pyEngine = site._AddEngine("Python")
#  pyEngine2 = site._AddEngine("Python")
  vbEngine = site._AddEngine("VBScript")
#  forthEngine = site._AddEngine("ForthScript")
  try:
#    code = open(os.path.join(scriptDir, "debugTest.4ths"),"rb").read()
#    forthEngine.AddCode(code)
    code = open(os.path.join(scriptDir, "debugTest.pys"),"rb").read()
    pyEngine.AddCode(code)
    code = open(os.path.join(scriptDir, "debugTest.vbs"),"rb").read()
    vbEngine.AddCode(code)
#    code = open(os.path.join(scriptDir, "debugTestFail.pys"),"rb").read()
#    pyEngine2.AddCode(code)

#    from win32com.axdebug import axdebug
#    sessionProvider=pythoncom.CoCreateInstance(axdebug.CLSID_DefaultDebugSessionProvider,None,pythoncom.CLSCTX_ALL, axdebug.IID_IDebugSessionProvider)
#    sessionProvider.StartDebugSession(None)

    raw_input("Press enter to continue")
 #   forthEngine.Start()
    pyEngine.Start() # Actually run the Python code
    vbEngine.Start() # Actually run the VB code
  except pythoncom.com_error, details:
    print "Script failed: %s (0x%x)" % (details[1], details[0])
  # Now run the code expected to fail!
#  try:
#    pyEngine2.Start() # Actually run the Python code that fails!
#    print "Script code worked when it should have failed."
#  except pythoncom.com_error:
#    pass

  site._Close()
dump.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def dumpall():
    dm=pythoncom.CoCreateInstance(axdebug.CLSID_MachineDebugManager,None,pythoncom.CLSCTX_ALL, axdebug.IID_IMachineDebugManager)
    e=Enumerator(dm.EnumApplications())
    for app in e:
        print "Application: %s" % app.GetName()
        node = app.GetRootNode() # of type PyIDebugApplicationNode->PyIDebugDocumentProvider->PyIDebugDocumentInfo
        DumpDebugApplicationNode(node)
combrowse.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def GetSubList(self):
        catinf=pythoncom.CoCreateInstance(pythoncom.CLSID_StdComponentCategoriesMgr,None,pythoncom.CLSCTX_INPROC,pythoncom.IID_ICatInformation)
        enum=util.Enumerator(catinf.EnumCategories())
        ret = []
        try:
            for catid, lcid, desc in enum:
                ret.append(HLICategory((catid, lcid, desc)))
        except pythoncom.com_error:
            # Registered categories occasionally seem to give spurious errors.
            pass # Use what we already have.
        return ret
combrowse.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def GetSubList(self):
        win32ui.DoWaitCursor(1)
        catid, lcid, desc = self.myobject
        catinf=pythoncom.CoCreateInstance(pythoncom.CLSID_StdComponentCategoriesMgr,None,pythoncom.CLSCTX_INPROC,pythoncom.IID_ICatInformation)
        ret = []
        for clsid in util.Enumerator(catinf.EnumClassesOfCategories((catid,),())):
            ret.append(HLICLSID(clsid))
        win32ui.DoWaitCursor(0)

        return ret
dynamic.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _GetGoodDispatch(IDispatch, clsctx = pythoncom.CLSCTX_SERVER):
    # quick return for most common case
    if isinstance(IDispatch, PyIDispatchType):
        return IDispatch
    if isinstance(IDispatch, _GoodDispatchTypes):
        try:
            IDispatch = pythoncom.connect(IDispatch)
        except pythoncom.ole_error:
            IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
    else:
        # may already be a wrapped class.
        IDispatch = getattr(IDispatch, "_oleobj_", IDispatch)
    return IDispatch
testPyComTest.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def TestVTable(clsctx=pythoncom.CLSCTX_ALL):
    # Any vtable interfaces marked as dual *should* be able to be
    # correctly implemented as IDispatch.
    ob = win32com.client.Dispatch("Python.Test.PyCOMTest")
    TestLocalVTable(ob)
    # Now test it via vtable - use some C++ code to help here as Python can't do it directly yet.
    tester = win32com.client.Dispatch("PyCOMTest.PyCOMTest")
    testee = pythoncom.CoCreateInstance("Python.Test.PyCOMTest", None, clsctx, pythoncom.IID_IUnknown)
    # check we fail gracefully with None passed.
    try:
        tester.TestMyInterface(None)
    except pythoncom.com_error, details:
        pass
    # and a real object.
    tester.TestMyInterface(testee)
testPyComTest.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def TestVTable2():
    # We once crashed creating our object with the native interface as
    # the first IID specified.  We must do it _after_ the tests, so that
    # Python has already had the gateway registered from last run.
    ob = win32com.client.Dispatch("Python.Test.PyCOMTest")
    iid = pythoncom.InterfaceNames["IPyCOMTest"]
    clsid = "Python.Test.PyCOMTest"
    clsctx = pythoncom.CLSCTX_SERVER
    try:
        testee = pythoncom.CoCreateInstance(clsid, None, clsctx, iid)
    except TypeError:
        # Python can't actually _use_ this interface yet, so this is
        # "expected".  Any COM error is not.
        pass
testGIT.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def CreateGIT():
    return pythoncom.CoCreateInstance(pythoncom.CLSID_StdGlobalInterfaceTable,
                                      None,
                                      pythoncom.CLSCTX_INPROC,
                                      pythoncom.IID_IGlobalInterfaceTable)
create_link.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__( self ):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
        )
dump_link.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def DumpLink(fname):
    shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
    persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
    persistFile.Load(fname,STGM_READ)
    shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
    fname, findData = shellLink.GetPath(0)
    print("Filename:", fname, ", UNC=", shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0])
    print("Description:", shellLink.GetDescription())
    print("Working Directory:", shellLink.GetWorkingDirectory())
    print("Icon:", shellLink.GetIconLocation())
IUniformResourceLocator.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__( self ):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_InternetShortcut, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IUniformResourceLocator
        )
axsite.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, site, engine):
    self.eScript = self.eParse = self.eSafety = None
    if type(engine) == type(''):
      engine = pythoncom.CoCreateInstance(engine,
                                          None,
                                          pythoncom.CLSCTX_SERVER,
                                          pythoncom.IID_IUnknown)

    self.eScript = engine.QueryInterface(axscript.IID_IActiveScript)
    self.eParse = engine.QueryInterface(axscript.IID_IActiveScriptParse)
    self.eSafety = engine.QueryInterface(axscript.IID_IObjectSafety)

    self.eScript.SetScriptSite(site)
    self.eParse.InitNew()
testHost4Dbg.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def TestEngine():
  model = {'Test' : util.wrap(ObjectModel()) }
  scriptDir = "."
  site = MySite(model)
  pyEngine = site._AddEngine("Python")
#  pyEngine2 = site._AddEngine("Python")
  vbEngine = site._AddEngine("VBScript")
#  forthEngine = site._AddEngine("ForthScript")
  try:
#    code = open(os.path.join(scriptDir, "debugTest.4ths"),"rb").read()
#    forthEngine.AddCode(code)
    code = open(os.path.join(scriptDir, "debugTest.pys"),"rb").read()
    pyEngine.AddCode(code)
    code = open(os.path.join(scriptDir, "debugTest.vbs"),"rb").read()
    vbEngine.AddCode(code)
#    code = open(os.path.join(scriptDir, "debugTestFail.pys"),"rb").read()
#    pyEngine2.AddCode(code)

#    from win32com.axdebug import axdebug
#    sessionProvider=pythoncom.CoCreateInstance(axdebug.CLSID_DefaultDebugSessionProvider,None,pythoncom.CLSCTX_ALL, axdebug.IID_IDebugSessionProvider)
#    sessionProvider.StartDebugSession(None)

    input("Press enter to continue")
 #   forthEngine.Start()
    pyEngine.Start() # Actually run the Python code
    vbEngine.Start() # Actually run the VB code
  except pythoncom.com_error as details:
    print("Script failed: %s (0x%x)" % (details[1], details[0]))
  # Now run the code expected to fail!
#  try:
#    pyEngine2.Start() # Actually run the Python code that fails!
#    print "Script code worked when it should have failed."
#  except pythoncom.com_error:
#    pass

  site._Close()
dump.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def dumpall():
    dm=pythoncom.CoCreateInstance(axdebug.CLSID_MachineDebugManager,None,pythoncom.CLSCTX_ALL, axdebug.IID_IMachineDebugManager)
    e=Enumerator(dm.EnumApplications())
    for app in e:
        print("Application: %s" % app.GetName())
        node = app.GetRootNode() # of type PyIDebugApplicationNode->PyIDebugDocumentProvider->PyIDebugDocumentInfo
        DumpDebugApplicationNode(node)
register.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _cat_registrar():
  return pythoncom.CoCreateInstance(
    pythoncom.CLSID_StdComponentCategoriesMgr,
    None,
    pythoncom.CLSCTX_INPROC_SERVER,
    pythoncom.IID_ICatRegister
    )
combrowse.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def GetSubList(self):
        win32ui.DoWaitCursor(1)
        catid, lcid, desc = self.myobject
        catinf=pythoncom.CoCreateInstance(pythoncom.CLSID_StdComponentCategoriesMgr,None,pythoncom.CLSCTX_INPROC,pythoncom.IID_ICatInformation)
        ret = []
        for clsid in util.Enumerator(catinf.EnumClassesOfCategories((catid,),())):
            ret.append(HLICLSID(clsid))
        win32ui.DoWaitCursor(0)

        return ret


问题


面经


文章

微信
公众号

扫码关注公众号