Re: [python-win32] Making a COM server that accepts COM objects
I changed to an InProcess server, which doesn't seem to work any better or worse than the LocalServer. Here's the trace: --- Object with win32trace dispatcher created (object=None) in ._QueryInterface_ with unsupported IID b'IPersistStreamInit' ({7FD52380-4E07-101B-AE2D-08002B2EC713}) in ._QueryInterface_ with unsupported IID b'IPersistPropertyBag' ({37D84F60-42CB-11CE-8135-00AA004BB851}) in _GetIDsOfNames_ with '('Barney',)' and '1033' in _Invoke_ with 1001 1033 3 (, ) Traceback (most recent call last): File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\dispatcher.py", line 47, in _Invoke_ return self.policy._Invoke_(dispid, lcid, wFlags, args) File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 278, in _Invoke_ return self._invoke_(dispid, lcid, wFlags, args) File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 283, in _invoke_ return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None) File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 586, in _invokeex_ return func(*args) File "C:\Users\rdboylan\Documents\Wk devel\BSTImport.py", line 37, in Barney rst = fedb.OpenRecordset("foo") AttributeError: 'PyIDispatch' object has no attribute 'OpenRecordset' pythoncom error: Python error invoking COM method. Traceback (most recent call last): File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\dispatcher.py", line 163, in _Invoke_ return DispatcherBase._Invoke_(self, dispid, lcid, wFlags, args) File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\dispatcher.py", line 49, in _Invoke_ return self._HandleException_() File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\dispatcher.py", line 47, in _Invoke_ return self.policy._Invoke_(dispid, lcid, wFlags, args) File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 278, in _Invoke_ return self._invoke_(dispid, lcid, wFlags, args) File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 283, in _invoke_ return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None) File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 586, in _invokeex_ return func(*args) File "C:\Users\rdboylan\Documents\Wk devel\BSTImport.py", line 37, in Barney rst = fedb.OpenRecordset("foo") AttributeError: 'PyIDispatch' object has no attribute 'OpenRecordset' --- To try to ensure that the old LocalServer wasn't active I did --unregister first, and restarted the calling program after that. I first tried commenting out #_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER when that didn't work I renamed the registry key LocalServer32 (I think; it's gone now) to NoLocalServer32. when that didn't work I set _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER and did the unregister/register, verifying there was no reference to the local server in the registry after. Ross From: python-win32 on behalf of Tim Roberts Sent: Wednesday, January 9, 2019 10:05:53 AM To: Python-Win32 List Subject: Re: [python-win32] Making a COM server that accepts COM objects Boylan, Ross wrote: > I have a Python 3.7, 32 bit, COM server and am calling it from 32 bit Office > 2010 in VBA. I am attempting to pass some COM objects from VBA to Python. > The trace collector full output appears below, but I think the key clues are > several messages like > > in ._QueryInterface_ with > unsupported IID {0003---C000-0046} > ({0003---C000-0046}) Those are not important. The COM framework is just probing to find out what extras you support. 0003-etc is IMarshal and 001B-etc is IStandardMarshal; both can be used to help in the RPC process. > and, later, > rst = fedb.OpenRecordset("foo") > AttributeError: 'PyIDispatch' object has no attribute 'OpenRecordset' You can't just pass an Access database object to another process and expect it to work. The support pieces aren't there. Thus, the crux of your problem is this: > _reg_progid_ = "Fahy.BST" > # for unknown reasons the inprocess serv
Re: [python-win32] Making a COM server that accepts COM objects
Boylan, Ross wrote: I have a Python 3.7, 32 bit, COM server and am calling it from 32 bit Office 2010 in VBA. I am attempting to pass some COM objects from VBA to Python. The trace collector full output appears below, but I think the key clues are several messages like in ._QueryInterface_ with unsupported IID {0003---C000-0046} ({0003---C000-0046}) Those are not important. The COM framework is just probing to find out what extras you support. 0003-etc is IMarshal and 001B-etc is IStandardMarshal; both can be used to help in the RPC process. and, later, rst = fedb.OpenRecordset("foo") AttributeError: 'PyIDispatch' object has no attribute 'OpenRecordset' You can't just pass an Access database object to another process and expect it to work. The support pieces aren't there. Thus, the crux of your problem is this: _reg_progid_ = "Fahy.BST" # for unknown reasons the inprocess server isn't working _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER That's the problem you need to chase. You need to be an in-process server if you want to share state with the original code. What happens when you register yourself as in-process? Note that the registry has to look different for this. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. smime.p7s Description: S/MIME Cryptographic Signature ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
[python-win32] Making a COM server that accepts COM objects
I have a Python 3.7, 32 bit, COM server and am calling it from 32 bit Office 2010 in VBA. I am attempting to pass some COM objects from VBA to Python. The trace collector full output appears below, but I think the key clues are several messages like in ._QueryInterface_ with unsupported IID {0003---C000-0046} ({0003---C000-0046}) and, later, rst = fedb.OpenRecordset("foo") AttributeError: 'PyIDispatch' object has no attribute 'OpenRecordset' I think this means that the objects passed in have unrecognized types, and therefore type-specific methods don't work on them (though it seems odd they aren't dynamically dispatched). What can I do to fix or debug this? Based on this theory, I used the makepy tool from the GUI to import the DAO 3.6 library, which I believe defines both types. But this didn't seem to help. I found some documentation saying to use win32com.client.Dispatch to get the right interface--it also mentioned that the IDispatch object would only repond to the 2 methods it knows--but I don't know how. All the examples I've seen with Dispatch use it to create a new object. I can't find any documentation on it (as opposed to tutorials illustratin it use); I think com\win32com\client\__init__.py has the relevant definition in the source code, but it is not apparent to me whether handing it an IDispatch object rather "Company.Class" will cause the appropriate object to be created. Running on 64 bit Win 7, with quite a few installations of versions of Python floating around. Using a LocalServer because of earlier problems with in process servers. In particular, the invoking path in the registry for my class is C:\PROGRA~2\PYTHON~1\pythonw.exe "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\localserver.py" even though I just installed pywin32 and it said it was putting things under "c:\Program Files (x86)". Both locations (with suitable additions to the Program Files path) have localserver.py --- test code in VBA Public Function medium() Dim srv As Object Set srv = CreateObject("Fahy.BST") medium = srv.Barney(DBEngine.Workspaces(0), CurrentDb()) End Function - python server code BSTImport.py --- import atexit, csv, sys import pythoncom, win32com.client from win32com.server.exception import COMException from win32com.client import constants from win32com.server.register import UseCommandLine TmpTable = "aatmpt_bst" # table to import csv into #pdb.set_trace() # fields in csv file I use now are # 'Sample Barcode', 'Participant ID', 'Initials', 'Visit ID', # 'Collection Date', 'Sample Type', 'Site Comment', # 'Shipment Comment', 'Shipment ID # BST Import already name of form in VB class BSTImport: # COM Support _public_methods_ = ['Fred', 'Barney'] _reg_clsid_ = "{050321C2-9B99-4CD0-B5E9-B636DFD94C4D}" _reg_desc_ = "BST Test Com Server in Python 32 bit" _reg_progid_ = "Fahy.BST" # for unknown reasons the inprocess server isn't working _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER def Barney(self, ws, fedb): """ws is the workspace with which a transaction has already been initiated fedb is the database used by the frontend""" rst = fedb.OpenRecordset("foo") rst.AddNew() fld = rst("foolish") fld.Value = "python.Barney" rst.Update() rst.Close() rst = None return True # other methods omitted if __name__ == "__main__": UseCommandLine(BSTImport) --- --- trace - Object with win32trace dispatcher created (object=None) in ._QueryInterface_ with unsupported IID {0003---C000-0046} ({0003---C000-0046}) in ._QueryInterface_ with unsupported IID {001B---C000-0046} ({001B---C000-0046}) in ._QueryInterface_ with unsupported IID {0018---C000-0046} ({0018---C000-0046}) in ._QueryInterface_ with unsupported IID b'IExternalConnection' ({0019---C000-0046}) in ._QueryInterface_ with unsupported IID {4C1E39E1-E3E3-4296-AA86-EC938D896E92} ({4C1E39E1-E3E3-4296-AA86-EC938D896E92}) in ._QueryInterface_ with unsupported IID b'IPersistStreamInit' ({7FD52380-4E07-101B-AE2D-08002B2EC713}) in ._QueryInterface_ with unsupported IID b'IPersistPropertyBag' ({37D84F60-42CB-11CE-8135-00AA004BB851}) in ._QueryInterface_ with unsupported IID {1C733A30-2A1C-11CE-ADE5-00AA0044773D} ({1C733A30-2A1C-11CE-ADE5-00AA0044773D}) in _GetIDsOfNames_ with '('Barney',)' and '1033' i