示例#1
0
def DispatchEx(clsid,
               machine=None,
               userName=None,
               resultCLSID=None,
               typeinfo=None,
               UnicodeToString=NeedUnicodeConversions,
               clsctx=None):
    """Creates a Dispatch based COM object on a specific machine.
  """
    # If InProc is registered, DCOM will use it regardless of the machine name
    # (and regardless of the DCOM config for the object.)  So unless the user
    # specifies otherwise, we exclude inproc apps when a remote machine is used.
    if clsctx is None:
        clsctx = pythoncom.CLSCTX_SERVER
        if machine is not None: clsctx = clsctx & ~pythoncom.CLSCTX_INPROC
    if machine is None:
        serverInfo = None
    else:
        serverInfo = (machine, )
    if userName is None: userName = clsid
    dispatch = pythoncom.CoCreateInstanceEx(clsid, None, clsctx, serverInfo,
                                            (pythoncom.IID_IDispatch, ))[0]
    return Dispatch(dispatch,
                    userName,
                    resultCLSID,
                    typeinfo,
                    UnicodeToString=UnicodeToString,
                    clsctx=clsctx)
示例#2
0
    def launch_binary(self):


        # (1) WinExec?
        # No need to run -WinExec- as -Dispatch- apparently does everything
        #win32api.WinExec(self.stata_fn, win32con.SW_SHOWMINNOACTIVE)

        # (2) EnsureModule?
        # C:\Bin\Python37\Lib\site-packages\win32com\client>makepy -v -i "stata.StataOLEApp"
        # stata
        #  {76656110-CB0F-44B4-90D2-D584B6768509}, lcid=0, major=1, minor=2
        #  >>> # Use these commands in Python code to auto generate .py support
        #  >>> from win32com.client import gencache
        #  >>> gencache.EnsureModule('{76656110-CB0F-44B4-90D2-D584B6768509}', 0, 1, 2)
        #mod = win32com.client.gencache.EnsureModule('{76656110-CB0F-44B4-90D2-D584B6768509}', 0, 1, 2)

        # (3) Dispatch; three options

        # (3a) Static cache
        # https://stackoverflow.com/a/36711595/3977107
        clsid = "stata.StataOLEApp"
        clsid = pythoncom.CoCreateInstanceEx(clsid, None, pythoncom.CLSCTX_SERVER,
                                             None, (pythoncom.IID_IDispatch,))[0]
        if win32com.client.gencache.is_readonly:
            #fix for "freezed" app: py2exe.org/index.cgi/UsingEnsureDispatch
            win32com.client.gencache.is_readonly = False
            win32com.client.gencache.Rebuild()
        self.exe = win32com.client.gencache.EnsureDispatch(clsid)