[python-win32] Creating COM objects in a new process
Wuping Xin
oudouxin at gmail.com
Mon Feb 26 12:57:46 EST 2024
This is related the COM instance model implemented on the COM server
side, not on the client side. Specifically, in the start-up code of
the COM server application, there should be a call to
CoRegisterClassObject(CLSID, pUnk, dwClsContext, flags, &dwRegister).
The key point is the fourth parameter “flags”. It determines during
run-time whether the COM server exe can be started as single instance or
multiple instances.
See this MSDN for more details:
https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coregisterclassobject?redirectedfrom=MSDN
Bottom line, this depends on the COM server implementation, not
something the client side can control.
Wuping
------ Original Message ------
>Date: Mon, 26 Feb 2024 20:12:29 +1100
>From: Aviv Bergman <bergmana at gmail.com>
>To: python-win32 at python.org
>Subject: [python-win32] Creating COM objects in a new process
>Message-ID: <394b0459-dd10-42fb-a1c9-2e70066eeb43 at gmail.com>
>Content-Type: text/plain; charset=UTF-8; format=flowed
>
>Hi
>
>
>I'm trying to create several COM objects, each in a new process, but it
>seems DispatchEx is reusing the existing COM server process, is there
>any way to force creating new objects in a new process?
>
>
>I'm using a python COM server,? minimal example attached
>
>Thanks
>Aviv
>
>---------
>
>import os
>import pythoncom
>
>class CTest:
> ??? _reg_progid_ = "STO.test"
> ??? _reg_clsid_ = "{13704826-80EC-4205-ADCE-ADBE5B741731}"
> ??? _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
> ??? _public_methods_ = ["test"]
>
> ??? def __init__(self):
> ??????? pass
>
> ??? def test(self):
> ??????? return "process = " + str(os.getpid())
>
>
>if __name__ == "__main__":
> ??? import win32com.server.register
> ??? win32com.server.register.UseCommandLine(CTest)
>
>
> >>> import win32com.client
> >>> o1 = win32com.client.DispatchEx("STO.test")
> >>> o2 = win32com.client.DispatchEx("STO.test")
> >>> o1.test()
>'process = 26764'
> >>> o2.test()
>'process = 26764'
> >>>
>
>
>------------------------------
>
>Message: 2
>Date: Mon, 26 Feb 2024 10:24:51 -0500
>From: Mark Hammond <mhammond at skippinet.com.au>
>To: Aviv Bergman <bergmana at gmail.com>, python-win32 at python.org
>Subject: Re: [python-win32] Creating COM objects in a new process
>Message-ID: <71e75e18-eb08-46e2-bfc9-316f7290cf70 at skippinet.com.au>
>Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
>I'm not aware of anything, other than arranging for the existing process
>to terminate.
>
>Cheers,
>
>Mark
>
>On 2024-02-26 4:12 a.m., Aviv Bergman wrote:
>> Hi
>>
>>
>> I'm trying to create several COM objects, each in a new process, but
>> it seems DispatchEx is reusing the existing COM server process, is
>> there any way to force creating new objects in a new process?
>>
>>
>> I'm using a python COM server,? minimal example attached
>>
>> Thanks
>> Aviv
>>
>> ---------
>>
>> import os
>> import pythoncom
>>
>> class CTest:
>> ??? _reg_progid_ = "STO.test"
>> ??? _reg_clsid_ = "{13704826-80EC-4205-ADCE-ADBE5B741731}"
>> ??? _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
>> ??? _public_methods_ = ["test"]
>>
>> ??? def __init__(self):
>> ??????? pass
>>
>> ??? def test(self):
>> ??????? return "process = " + str(os.getpid())
>>
>>
>> if __name__ == "__main__":
>> ??? import win32com.server.register
>> ??? win32com.server.register.UseCommandLine(CTest)
>>
>>
>> >>> import win32com.client
>> >>> o1 = win32com.client.DispatchEx("STO.test")
>> >>> o2 = win32com.client.DispatchEx("STO.test")
>> >>> o1.test()
>> 'process = 26764'
>> >>> o2.test()
>> 'process = 26764'
>> >>>
>> _______________________________________________
>> python-win32 mailing list
>>python-win32 at python.org
>>https://mail.python.org/mailman/listinfo/python-win32
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: <https://mail.python.org/pipermail/python-win32/attachments/20240226/1bffda99/attachment-0001.html>
>
>------------------------------
>
>Subject: Digest Footer
>
>_______________________________________________
>python-win32 mailing list
>python-win32 at python.org
>https://mail.python.org/mailman/listinfo/python-win32
>
>
>------------------------------
>
>End of python-win32 Digest, Vol 247, Issue 3
>********************************************
More information about the python-win32
mailing list