[python-win32] Calling COM methods that expect arguments by reference

Aaron Hoover amhoov at gmail.com
Tue Aug 11 02:41:16 CEST 2009


Hi Greg,

I gave your suggestion a shot, but I get the following perplexing error:

TypeError: int() argument must be a string or a number, not 'NoneType'


which makes me think it's still somehow expecting to get those values  
as input even though they're explicitly set to be outputs in the  
generated file.

I'll dig a bit deeper tomorrow to see what I can come up with.

Thanks,
Aaron

On Aug 10, 2009, at 2:30 PM, Greg Antal wrote:

> Aaron:
>
> From the Python definition you show, PythonCOM is going to treat  
> your call-by-reference arguments as output values whether they're  
> supposed to be or not.  This is for all the parameters defined with  
> type (16387, 2).
>
> When you have parameters identified like that, your Python call has  
> to treat them as return values, not as calling arguments.  In your  
> case, that means your call should look like   Rows, Cols, X0, Y0,  
> Xext, Yext, ErrCode = app.TileGraphic (9, 0, 0, "Test.dxf",  
> "Results", 1.0, 940.0, 0) .
>
> Of course, that may not actually solve all your problems.  Mike  
> Graham and I had ongoing trouble even after we got the calling  
> sequence right, for completely different reasons.   If that happens  
> to you, I'm afraid you'll have to get advice from someone much wiser  
> than I.  (There are a lot of them monitoring this list, fortunately.)
>
> - Greg Antal
>  Gregory W. Antal
> Senior Technical Advisor
> ATA Engineering, Inc.
> 11995 El Camino Real, Suite 200	
> San Diego, CA  92130
> www.ata-e.com
>
> greg.antal at ata-e.com
> 858-480-2072  (Phone)
> 858-792-8932  (Fax)
>
>
> Aaron Hoover wrote, On 8/10/2009 1:34 PM:
>>
>> This question is similar to one posed by Mike Graham in a recent  
>> thread, but I thought I'd see if I could rustle up any additional  
>> feedback.
>>
>> I'm trying to called a COM automation object using Python. The  
>> wrinkle is that the method I need uses arguments by reference to  
>> store output from its execution. The signature looks like this:
>>
>> TileGraphic(int FileType, int Margin, intObjMargin, BSTR FileName,  
>> BSTR DestName, float KFactor1, float KFactor2, int* Rows, int*  
>> Columns, int* X0, int* Y0, int* XExtent, int* YExtent, long  
>> InMemory, int* ErrorCode)
>>
>>
>> The Python code generated by makepy looks like:
>>
>> def TileGraphic(self, FileType=defaultNamedNotOptArg,  
>> Margin=defaultNamedNotOptArg, ObjMargin=defaultNamedNotOptArg,  
>> FileName=defaultNamedNotOptArg
>>  , DestName=defaultNamedNotOptArg, KFactor1=defaultNamedNotOptArg,  
>> KFactor2=defaultNamedNotOptArg, Rows=pythoncom.Missing,  
>> Columns=pythoncom.Missing
>>  , X0=pythoncom.Missing, Y0=pythoncom.Missing,  
>> XExtent=pythoncom.Missing, YExtent=pythoncom.Missing,  
>> InMemory=defaultNamedNotOptArg
>>  , ErrorCode=pythoncom.Missing):
>>  return self._ApplyTypes_(125, 1, (24, 0), ((3, 1), (3, 1), (3, 1),  
>> (8, 1), (8, 1), (4, 1), (4, 1), (16387, 2), (16387, 2), (16387, 2),  
>> (16387, 2), (16387, 2), (16387, 2), (3, 1), (16387,
>>  2)), 'TileGraphic', None,FileType
>>  , Margin, ObjMargin, FileName, DestName, KFactor1
>>  , KFactor2, Rows, Columns, X0, Y0
>>  , XExtent, YExtent, InMemory, ErrorCode)
>>
>>
>> I'm somewhat unsure how to call it. If I just pass in variables  
>> with integer values for the by reference arguments, this is the  
>> output:
>>
>> ## All args after 940.0 are just variables containing integers
>>
>>
>> >>> app.TileGraphic(9, 0, 0, "Test.dxf", "Results", 1.0, 940.0,  
>> rows, cols,
>> x0, y0, xExtent, yExtent, 0, ErrorCode)
>> ERROR: An unexpected error occurred while tokenizing input
>> The following traceback may be corrupted or invalid
>> The error message is: ('EOF in multi-line statement', (156, 0))
>>
>> ---------------------------------------------------------------------------
>> com_error                                 Traceback (most recent  
>> call last)
>>
>> c:\users\aaron\code\<ipython console> in <module>()
>>
>> C:\Python25\lib\site-packages\pywin32-210n1-py2.5-win32.egg\win32com 
>> \gen_py\DAE1
>> 337F-69EF-4233-B4E3-27C348C3D9D6x0x1x0.pyc in TileGraphic(self,  
>> FileType, Margin
>> , ObjMargin, FileName, DestName, KFactor1, KFactor2, Rows, Columns,  
>> X0, Y0, XExt
>> ent, YExtent, InMemory, ErrorCode)
>>     648                         , Margin, ObjMargin, FileName,  
>> DestName, KFactor
>> 1
>>     649                         , KFactor2, Rows, Columns, X0, Y0
>> --> 650                         , XExtent, YExtent, InMemory,  
>> ErrorCode)
>>     651
>>     652         def TurnLaserOff(self,  
>> CardNum=defaultNamedNotOptArg):
>>
>> C:\Python25\lib\site-packages\pywin32-210n1-py2.5-win32.egg\win32com 
>> \client\__in
>> it__.pyc in _ApplyTypes_(self, dispid, wFlags, retType, argTypes,  
>> user, resultCL
>> SID, *args)
>>     446                 return self._get_good_object_(
>>     447                     self._oleobj_.InvokeTypes(
>> --> 448                               dispid, 0, wFlags, retType,  
>> argTypes, *arg
>> s),
>>     449                     user, resultCLSID)
>>     450
>>
>> com_error: (-2147352567, 'Exception occurred.', (0,  
>> 'winlase.Automate', 'Error d
>> uring Tiling', None, 0, -2147467259), None)
>>
>>
>> I have also tried using pythoncom.Missing and pythoncom.ArgNotFound  
>> per Mark Hammond's suggestion. I thought by reference input  
>> variables were supposed to be converted to output tuples by makepy.  
>> Am I missing something here? If I try and execute the method  
>> without any of the input reference variables, I get this error:
>>
>> TypeError: int() argument must be a string or a number, not  
>> 'NoneType'
>>
>>
>>
>> _______________________________________________
>> python-win32 mailing list
>> python-win32 at python.org
>> http://mail.python.org/mailman/listinfo/python-win32
>>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20090810/ce1554ee/attachment-0001.htm>


More information about the python-win32 mailing list