Re: [python-win32] [win32com] Meaning of "TypeError: Only com_record objects can be used as records"?
Hi Tim, Thanks for the pointer! I'll let the maintainers of this software know. Do you know if applying this fix is sufficient for win32com to successfully handle returned structs? -Terry On Mon, Apr 27, 2020 at 11:32 PM Tim Roberts wrote: > > On Apr 27, 2020, at 12:58 PM, Terry Davis wrote: > > > > I looked in the generated file, and its RecordMap dict was empty, with a > comment. There are a dozen or so structs that should be available to the > interface. Is there any workaround for this, such as manually defining each > com_record? > > > > RecordMap = { > > ###'LegacyMicroSamplerInfo': '{----}', # > Record disabled because it doesn't have a non-null GUID > > } > > > > I was also given an idl file, which includes record definitions, like > this one: > > > > typedef struct SoftwareInfo { > >BSTR name; > >BSTR version; > > } SoftwareInfo; > > > > Is there something missing from the idl file that's causing these to be > missed by win32com? > > Well, yes. There are rigid rules for writing IDL to make a valid dispatch > interface, and generic structs like that are not in those rules. Some > people get the idea that anything they can express in C++ can be shoved in > a COM interface, but it ain’t so. > > You should be able to add a GUID attribute to the IDL: > > [ uuid(12345678-1234-1234-1234-123456789ABC) ] > typedef struct SoftwareInfo { > … > } SoftwareInfo; > > Just generate a new GUID for each one. > — > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc. > > ___ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] [win32com] Meaning of "TypeError: Only com_record objects can be used as records"?
I just discovered this message: https://mail.python.org/pipermail/python-list/2003-August/214888.html and when I tried getting a com_record: client.Record("SoftwareInfo",app._com) I got this error: ValueError: The structure 'SoftwareInfo' is not defined in module 'x1x0' I looked in the generated file, and its RecordMap dict was empty, with a comment. There are a dozen or so structs that should be available to the interface. Is there any workaround for this, such as manually defining each com_record? RecordMap = { ###'LegacyMicroSamplerInfo': '{----}', # Record disabled because it doesn't have a non-null GUID } I was also given an idl file, which includes record definitions, like this one: typedef struct SoftwareInfo { BSTR name; BSTR version; } SoftwareInfo; Is there something missing from the idl file that's causing these to be missed by win32com? On Wed, Apr 22, 2020 at 9:28 AM Terry Davis wrote: > Any ideas? > > On Tue, Jan 28, 2020 at 1:06 PM Terry Davis > wrote: > >> Update 2: After discovering the `pythoncom.GetRecordFromGuids` and >> `.GetRecordFromTypeInfo` (with the comment: "This function will fail if the >> specified type info does not have a guid defined"). >> >> I found that the Record types don't appear to have a GUID. >> lib_pyITypelib.GetDocumentation(4) = ('SoftwareInfo', None, 0, None) >> lib_pyITypelib.GetTypeInfo(4).GetTypeAttr().iid >> = IID('{----}') >> >> So, is it possible to create a Record object without a GUID? >> (Assuming that passing a Record object `ccs.GetSoftwareInfo(info=> Record Object>)` is the correct approach here.) >> >> I also tried assigning a `pythoncom.CreateGuid() to the `iid` attribute >> above, but `GetRecordFromGuids` failed with `pywintypes.com_error: >> (-2147319765, 'Element not found.', None, None)`. So I assume the GUID >> assignment didn't make it outside of python into COM-space. >> >> P.S. >> I also found this old thread: >> >> https://grokbase.com/t/python/python-win32/0821b2n4e5/how-to-create-a-com-record >> which appears to be related to my problem, but no solutions were >> identified. >> (I tried the `DumbDispatch` solution; it didn't work). >> >> >> On Mon, Jan 27, 2020 at 4:31 PM Terry Davis >> wrote: >> >>> Update: The functions that don't work return Record types, and the ones >>> that do work just return multiple values (a tuple). >>> Do I need to pass in the appropriate Record type (or an empty record) >>> during each function call? >>> If so, how do I get to the Record types that I see in the python object >>> browser (python -m win32com.client.combrowse)? >>> >>> Thanks, >>> Terry >>> >>> On Mon, Jan 27, 2020 at 3:33 PM Terry Davis >>> wrote: >>> >>>> Hi all, >>>> >>>> I tried searching the mailing list archives for "com_record" but didn't >>>> find anything relevant. >>>> >>>> For context, I'm trying to access a COM interface defined in a .tlb >>>> file. >>>> >>>> Here's a skeleton of the script I'm using to expose this interface: >>>> import pythoncom >>>> from win32com.client import gencache >>>> >>>> lib_GUID = "{}" >>>> lib_major = 1 >>>> lib_minor = 0 >>>> lib_pyITypelib = pythoncom.LoadRegTypeLib(lib_GUID, lib_major, >>>> lib_minor) >>>> lib = gencache.EnsureModuleForTypelibInterface(_lib_pyITypelib) >>>> >>>> ccs = lib.CControlServer() # CControlServer is a CoClass >>>> eid, *other = ccs.LoadExperiment(**path to file**) # Works >>>> ccs.GetSoftwareInfo() # Fails with exception below. >>>> ccs.GetSolvent(eid) # also fails >>>> >>>> I can't dig down in the debugger to find the source of the exception, >>>> so I'm hoping someone here can help! >>>> >>>> >>>> Exception: >>>> >>>> def GetSoftwareInfo(self, info=pythoncom.Missing): >>>> >>>> >>>> in >>>> > 1 ccs.GetSoftwareInfo() >>>> >>>> ~\AppData\Local\Temp\gen_py\3.7\x0x1x0.py in >>>> GetSoftwareInfo(self, info) >>>> 279 def GetSoftwareInfo(self, info=pythoncom.Missing): >>>> 280 'method GetSoftwareInfo' >>>> --> 281 return self._ApplyTypes_(13, 1, (24, 0), ((36, >>>> 2),), 'GetSoftwareInfo', None,info >>>> 282 ) >>>> 283 >>>> >>>> C:\Python37\lib\site-packages\win32com\client\__init__.py in >>>> _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, >>>> *args) >>>> 465 def _ApplyTypes_(self, dispid, wFlags, retType, >>>> argTypes, user, resultCLSID, *args): >>>> 466 return self._get_good_object_( >>>> --> 467 self._oleobj_.InvokeTypes(dispid, 0, >>>> wFlags, retType, argTypes, *args), >>>> 468 user, resultCLSID) >>>> 469 >>>> >>>> TypeError: Only com_record objects can be used as records >>>> >>> ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] [win32com] Meaning of "TypeError: Only com_record objects can be used as records"?
Any ideas? On Tue, Jan 28, 2020 at 1:06 PM Terry Davis wrote: > Update 2: After discovering the `pythoncom.GetRecordFromGuids` and > `.GetRecordFromTypeInfo` (with the comment: "This function will fail if the > specified type info does not have a guid defined"). > > I found that the Record types don't appear to have a GUID. > lib_pyITypelib.GetDocumentation(4) = ('SoftwareInfo', None, 0, None) > lib_pyITypelib.GetTypeInfo(4).GetTypeAttr().iid > = IID('{----}') > > So, is it possible to create a Record object without a GUID? > (Assuming that passing a Record object `ccs.GetSoftwareInfo(info= Record Object>)` is the correct approach here.) > > I also tried assigning a `pythoncom.CreateGuid() to the `iid` attribute > above, but `GetRecordFromGuids` failed with `pywintypes.com_error: > (-2147319765, 'Element not found.', None, None)`. So I assume the GUID > assignment didn't make it outside of python into COM-space. > > P.S. > I also found this old thread: > > https://grokbase.com/t/python/python-win32/0821b2n4e5/how-to-create-a-com-record > which appears to be related to my problem, but no solutions were > identified. > (I tried the `DumbDispatch` solution; it didn't work). > > > On Mon, Jan 27, 2020 at 4:31 PM Terry Davis > wrote: > >> Update: The functions that don't work return Record types, and the ones >> that do work just return multiple values (a tuple). >> Do I need to pass in the appropriate Record type (or an empty record) >> during each function call? >> If so, how do I get to the Record types that I see in the python object >> browser (python -m win32com.client.combrowse)? >> >> Thanks, >> Terry >> >> On Mon, Jan 27, 2020 at 3:33 PM Terry Davis >> wrote: >> >>> Hi all, >>> >>> I tried searching the mailing list archives for "com_record" but didn't >>> find anything relevant. >>> >>> For context, I'm trying to access a COM interface defined in a .tlb file. >>> >>> Here's a skeleton of the script I'm using to expose this interface: >>> import pythoncom >>> from win32com.client import gencache >>> >>> lib_GUID = "{}" >>> lib_major = 1 >>> lib_minor = 0 >>> lib_pyITypelib = pythoncom.LoadRegTypeLib(lib_GUID, lib_major, lib_minor) >>> lib = gencache.EnsureModuleForTypelibInterface(_lib_pyITypelib) >>> >>> ccs = lib.CControlServer() # CControlServer is a CoClass >>> eid, *other = ccs.LoadExperiment(**path to file**) # Works >>> ccs.GetSoftwareInfo() # Fails with exception below. >>> ccs.GetSolvent(eid) # also fails >>> >>> I can't dig down in the debugger to find the source of the exception, so >>> I'm hoping someone here can help! >>> >>> >>> Exception: >>> >>> def GetSoftwareInfo(self, info=pythoncom.Missing): >>> >>> >>> in >>> > 1 ccs.GetSoftwareInfo() >>> >>> ~\AppData\Local\Temp\gen_py\3.7\x0x1x0.py in GetSoftwareInfo(self, >>> info) >>> 279 def GetSoftwareInfo(self, info=pythoncom.Missing): >>> 280 'method GetSoftwareInfo' >>> --> 281 return self._ApplyTypes_(13, 1, (24, 0), ((36, >>> 2),), 'GetSoftwareInfo', None,info >>> 282 ) >>> 283 >>> >>> C:\Python37\lib\site-packages\win32com\client\__init__.py in >>> _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, >>> *args) >>> 465 def _ApplyTypes_(self, dispid, wFlags, retType, >>> argTypes, user, resultCLSID, *args): >>> 466 return self._get_good_object_( >>> --> 467 self._oleobj_.InvokeTypes(dispid, 0, >>> wFlags, retType, argTypes, *args), >>> 468 user, resultCLSID) >>> 469 >>> >>> TypeError: Only com_record objects can be used as records >>> >> ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] determine the default printer from RDP
Hi John, In the Windows RDP client, under "Show Options" -> "Local Resources" -> section "Local devices and resources" is "Printers" checked? I haven't tried what you're referring to, but perhaps that setting is relevant to your problem? - Terry On Tue, Feb 25, 2020 at 5:51 PM john wrote: > Hi, > > I need a way to determine the default printer (on the users computer) from > a RDP session. > > The user logs on to a RDP session and win32print.GetDefaultPrinter() > returns a blank. That makes sense on the RDP session because there aren't > any default printers. RDP printing is directed to the default printer on > the users desktop. > > Is there a way to get the default printer from the RDP session. > > Johnf > ___ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] [win32com] Meaning of "TypeError: Only com_record objects can be used as records"?
Update 2: After discovering the `pythoncom.GetRecordFromGuids` and `.GetRecordFromTypeInfo` (with the comment: "This function will fail if the specified type info does not have a guid defined"). I found that the Record types don't appear to have a GUID. lib_pyITypelib.GetDocumentation(4) = ('SoftwareInfo', None, 0, None) lib_pyITypelib.GetTypeInfo(4).GetTypeAttr().iid = IID('{----}') So, is it possible to create a Record object without a GUID? (Assuming that passing a Record object `ccs.GetSoftwareInfo(info=)` is the correct approach here.) I also tried assigning a `pythoncom.CreateGuid() to the `iid` attribute above, but `GetRecordFromGuids` failed with `pywintypes.com_error: (-2147319765, 'Element not found.', None, None)`. So I assume the GUID assignment didn't make it outside of python into COM-space. P.S. I also found this old thread: https://grokbase.com/t/python/python-win32/0821b2n4e5/how-to-create-a-com-record which appears to be related to my problem, but no solutions were identified. (I tried the `DumbDispatch` solution; it didn't work). On Mon, Jan 27, 2020 at 4:31 PM Terry Davis wrote: > Update: The functions that don't work return Record types, and the ones > that do work just return multiple values (a tuple). > Do I need to pass in the appropriate Record type (or an empty record) > during each function call? > If so, how do I get to the Record types that I see in the python object > browser (python -m win32com.client.combrowse)? > > Thanks, > Terry > > On Mon, Jan 27, 2020 at 3:33 PM Terry Davis > wrote: > >> Hi all, >> >> I tried searching the mailing list archives for "com_record" but didn't >> find anything relevant. >> >> For context, I'm trying to access a COM interface defined in a .tlb file. >> >> Here's a skeleton of the script I'm using to expose this interface: >> import pythoncom >> from win32com.client import gencache >> >> lib_GUID = "{}" >> lib_major = 1 >> lib_minor = 0 >> lib_pyITypelib = pythoncom.LoadRegTypeLib(lib_GUID, lib_major, lib_minor) >> lib = gencache.EnsureModuleForTypelibInterface(_lib_pyITypelib) >> >> ccs = lib.CControlServer() # CControlServer is a CoClass >> eid, *other = ccs.LoadExperiment(**path to file**) # Works >> ccs.GetSoftwareInfo() # Fails with exception below. >> ccs.GetSolvent(eid) # also fails >> >> I can't dig down in the debugger to find the source of the exception, so >> I'm hoping someone here can help! >> >> >> Exception: >> >> def GetSoftwareInfo(self, info=pythoncom.Missing): >> >> >> in >> > 1 ccs.GetSoftwareInfo() >> >> ~\AppData\Local\Temp\gen_py\3.7\x0x1x0.py in GetSoftwareInfo(self, >> info) >> 279 def GetSoftwareInfo(self, info=pythoncom.Missing): >> 280 'method GetSoftwareInfo' >> --> 281 return self._ApplyTypes_(13, 1, (24, 0), ((36, >> 2),), 'GetSoftwareInfo', None,info >> 282 ) >> 283 >> >> C:\Python37\lib\site-packages\win32com\client\__init__.py in >> _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, >> *args) >> 465 def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, >> user, resultCLSID, *args): >> 466 return self._get_good_object_( >> --> 467 self._oleobj_.InvokeTypes(dispid, 0, >> wFlags, retType, argTypes, *args), >> 468 user, resultCLSID) >> 469 >> >> TypeError: Only com_record objects can be used as records >> > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
[python-win32] [win32com] Meaning of "TypeError: Only com_record objects can be used as records"?
Hi all, I tried searching the mailing list archives for "com_record" but didn't find anything relevant. For context, I'm trying to access a COM interface defined in a .tlb file. Here's a skeleton of the script I'm using to expose this interface: import pythoncom from win32com.client import gencache lib_GUID = "{}" lib_major = 1 lib_minor = 0 lib_pyITypelib = pythoncom.LoadRegTypeLib(lib_GUID, lib_major, lib_minor) lib = gencache.EnsureModuleForTypelibInterface(_lib_pyITypelib) ccs = lib.CControlServer() # CControlServer is a CoClass eid, *other = ccs.LoadExperiment(**path to file**) # Works ccs.GetSoftwareInfo() # Fails with exception below. ccs.GetSolvent(eid) # also fails I can't dig down in the debugger to find the source of the exception, so I'm hoping someone here can help! Exception: def GetSoftwareInfo(self, info=pythoncom.Missing): in > 1 ccs.GetSoftwareInfo() ~\AppData\Local\Temp\gen_py\3.7\x0x1x0.py in GetSoftwareInfo(self, info) 279 def GetSoftwareInfo(self, info=pythoncom.Missing): 280 'method GetSoftwareInfo' --> 281 return self._ApplyTypes_(13, 1, (24, 0), ((36, 2),), 'GetSoftwareInfo', None,info 282 ) 283 C:\Python37\lib\site-packages\win32com\client\__init__.py in _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args) 465 def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args): 466 return self._get_good_object_( --> 467 self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args), 468 user, resultCLSID) 469 TypeError: Only com_record objects can be used as records ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] [win32com] Meaning of "TypeError: Only com_record objects can be used as records"?
Update: The functions that don't work return Record types, and the ones that do work just return multiple values (a tuple). Do I need to pass in the appropriate Record type (or an empty record) during each function call? If so, how do I get to the Record types that I see in the python object browser (python -m win32com.client.combrowse)? Thanks, Terry On Mon, Jan 27, 2020 at 3:33 PM Terry Davis wrote: > Hi all, > > I tried searching the mailing list archives for "com_record" but didn't > find anything relevant. > > For context, I'm trying to access a COM interface defined in a .tlb file. > > Here's a skeleton of the script I'm using to expose this interface: > import pythoncom > from win32com.client import gencache > > lib_GUID = "{}" > lib_major = 1 > lib_minor = 0 > lib_pyITypelib = pythoncom.LoadRegTypeLib(lib_GUID, lib_major, lib_minor) > lib = gencache.EnsureModuleForTypelibInterface(_lib_pyITypelib) > > ccs = lib.CControlServer() # CControlServer is a CoClass > eid, *other = ccs.LoadExperiment(**path to file**) # Works > ccs.GetSoftwareInfo() # Fails with exception below. > ccs.GetSolvent(eid) # also fails > > I can't dig down in the debugger to find the source of the exception, so > I'm hoping someone here can help! > > > Exception: > > def GetSoftwareInfo(self, info=pythoncom.Missing): > > > in > > 1 ccs.GetSoftwareInfo() > > ~\AppData\Local\Temp\gen_py\3.7\x0x1x0.py in GetSoftwareInfo(self, > info) > 279 def GetSoftwareInfo(self, info=pythoncom.Missing): > 280 'method GetSoftwareInfo' > --> 281 return self._ApplyTypes_(13, 1, (24, 0), ((36, > 2),), 'GetSoftwareInfo', None,info > 282 ) > 283 > > C:\Python37\lib\site-packages\win32com\client\__init__.py in > _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, > *args) > 465 def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, > user, resultCLSID, *args): > 466 return self._get_good_object_( > --> 467 self._oleobj_.InvokeTypes(dispid, 0, > wFlags, retType, argTypes, *args), > 468 user, resultCLSID) > 469 > > TypeError: Only com_record objects can be used as records > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32