Éric Piel | 20 Jan 15:50
Picon
Picon
Favicon
Gravatar

Right way to call a method with a pointer to array?

Hello,

I'm in a similar situation of what was described previously in this thread:
http://sourceforge.net/mailarchive/message.php?msg_id=25175351

I need to send a pointer to a buffer which will be filled by the method 
as output. The IDL looks like this:
HRESULT GetImage([in] long lSize, [out, size_is(size)] BYTE *pbImage)

With the SVN head of comtypes, it's fairly easy to handle, but I still 
need to do two things:
* Change the generated python class to force pbImage to be 'in' and not 
'out'
* Cast my buffer variable to look like a pointer to a byte, and not an 
array:
   buffer = (c_ubyte * num_bytes)()
   c.GetImage(num_bytes, cast(pointer(buffer), POINTER(c_ubyte)))

So my question: is this the right way to do it?

Would it be possible to modify comptypes to make it easier?
  * Could it be possible to have the tlb parser to detect this case and 
put the parameter as 'in' instead of 'out'?
  * Could it be possible to support the byref() construct like:
   c.GetImage(num_bytes, byref(buffer))
   For now it raises a type exception:
ArgumentError: argument 2: <type 'exceptions.TypeError'>: expected 
LP_c_ubyte instance instead of pointer to c_ubyte_Array_226304

Thanks in advance for your help and input!
(Continue reading)

Picon

installing error

Dear all;

i am new comer of comtypes user.
i tried to install comtypes-0.6.2.win32.exe on my windows 7 64bit
notebook but got
an error message

ImportError: No module named __builtin__

the version of installed python is 2.7.2.
any comments or suggestions?

i also try svn checkout  source code from svn.sourceforge
and run python setup.py but failed and got an errror message

raceback (most recent call last):
  File "setup.py", line 42, in <module>
    from distutils.core import setup, Command, DistutilsOptionError
ImportError: cannot import name DistutilsOptionError

any idea?

thanks!
--

-- 
Jun-Liang

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model 
configuration take the hassle out of deploying and managing Subversion and 
the tools developers use with it. Learn more about uberSVN and get a free 
(Continue reading)

Adam Keys | 1 Jul 00:50
Picon

(no subject)

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
comtypes-users mailing list
comtypes-users@...
https://lists.sourceforge.net/lists/listinfo/comtypes-users
Erik Wilsher | 19 May 00:15
Picon

Problems with POINTER(_midlSAFEARRAY(BSTR))

I'm trying to call a third party library with comtypes automation. It
could seem that I have some problems to get the parameters passed into
the method right. In the documentation the "Validate" method is
described to recive an "array of strings" in the 'ItemIDs' argument.
The gen-cached signature is shown below:

    COMMETHOD([dispid(1610743822), helpstring(u'Validates a set of
item ids without adding them to the collection.')], HRESULT,
'Validate',
              ( ['in'], c_int, 'NumItems' ),
              ( ['in'], POINTER(_midlSAFEARRAY(BSTR)), 'ItemIDs' ),
              ( ['out'], POINTER(_midlSAFEARRAY(c_int)), 'Errors' ),
              ( ['in', 'optional'], VARIANT, 'RequestedDataTypes' ),
              ( ['in', 'optional'], VARIANT, 'AccessPaths' )),

I have tried (and searched for) a large number of variants to build
the 'ItemIDs' argument, including:

grp.Validate(1, ['Test.tag'])  #Naive - did not expect this to work

arr = _midlSAFEARRAY(comtypes.BSTR)
x=arr.from_param(('Test.tag',))
grp.Validate(1, x)    #nope
grp.Validate(1, pointer(x))   #no - not this one either

They all return:
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
COMError: (-2147024809, 'The parameter is incorrect.', (None, None,
None, 0, None))

Are there any suggestions what I could do about this?

I also have a similar problem in another method where I need to pass
an array of integers, defined as:

              ( ['in'], POINTER(_midlSAFEARRAY(c_int)), 'ServerHandles' ),

For this argument I've tried array.array('x', (...)) where x is
'i','l','I', and 'L', as well as other ways to build this parameter
without any success. Suggestions would be most helpful.

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
Lex | 13 Feb 10:58
Picon

Problem with dispatching events (works with win32com)

Hi all,

I am trying to port a piece of software from win32com to comtypes, 
because that's what we use in our project. Basically, I want to react on 
events generated by the Synaptics touchpad. Unfortunately, ShowEvents() 
doesn't show me actually any events when I generate them (e.g. press 
buttons or move fingers on the touchpad). On the other side, I can 
successfully consume events when use win32com package.
When I call ShowEvents on an object, it shows me that there is one event 
(OnPacket), but it doesn't notify when packet arrives.

Here are two little scripts, first uses win32com, and second uses 
comtypes. If you have Synaptics touchpad (Almost every notebook/netbook 
has it), run the scripts and try to perform something with your touchpad 
to generate events.

#testpad_old.py
from win32com.client import Dispatch, DispatchWithEvents, constants
import pythoncom

class SynDeviceTouchPadCtrlEvents:
     def OnPacket(self):
         print "on packed is called"

api = Dispatch('SynCtrl.SynAPICtrl')
api.Initialize()
api.Activate()
handle = api.FindDevice(constants.SE_ConnectionAny, 
constants.SE_DeviceTouchPad, -1)
if handle < 0:
     raise RuntimeError('Can\'t find a TouchPad device!')
touchpad = DispatchWithEvents('SynCtrl.SynDeviceCtrl', 
SynDeviceTouchPadCtrlEvents)
touchpad.Select(handle)
touchpad.Activate()
pythoncom.PumpMessages()

#testpad_new.py
from comtypes.client import CreateObject, ShowEvents, PumpEvents
import comtypes.gen.SYNCTRLLib as synlib

api=CreateObject('SynCtrl.SynAPICtrl')
api.initialize()
api.activate()
handle = api.FindDevice(synlib.SE_ConnectionAny, 
synlib.SE_DeviceTouchPad, -1)
if handle < 0:
     raise RuntimeError('Can\'t find a TouchPad device!')
touchpad=CreateObject('SynCtrl.SynDeviceCtrl')
conn=ShowEvents(touchpad) # event found: _ISynDeviceCtrlEvents_OnPacket
touchpad.select(handle)
touchpad.Activate()
PumpEvents(10)

I am using comtypes version 0.6.2. Is it a comtypes bug or mine?

Thanks,
Lex

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
Brad Buran | 25 Jan 08:43
Picon
Favicon

TypeError with numpy arrays

After using win32com for years, I stumbled across comtypes earlier
tonight.  My tests indicate that comtypes is significantly faster than
win32com for reading/writing large arrays of data between Python and
the COM object.  So far, all of the methods on the COM object work
nicely with comtypes except for one called WriteTagV.  The signature
of this method is:
long WriteTagV(LPCTSTR Name, long nOS, Variant &buffer);

When I attempt to execute the following code:
from comtypes import client
from numpy import array
interface = client.CreateObject('RPco.X')
data = array([1, 2, 3, 4, 5], dtype='f4')
interface.WriteTagV('data', 0, data)

I get the following error:

TypeError: Cannot put array([ 1.,  2.,  3.,  4.,  5.], dtype=float32) in VARIANT

Traceback is below my signature.

However, when I try the following

from array import array
data = array('d', [1, 2, 3, 4, 5])
interface.WriteTagV('data', 0, data)

It works just fine!

Is there something I need to do to get this working with Numpy ndarray
objects?  This method worked just fine with win32com and Numpy arrays.

Thanks!
Brad

Full traceback for the Numpy array case:

 c:\experiments\programs\python_lib\tdt\<ipython console> in <module>()

C:\Python26\lib\site-packages\comtypes\__init__.pyc in func(obj, *args, **kw)
    515         else:
    516             def func(obj, *args, **kw):
--> 517                 return self.Invoke(obj, memid, _invkind=1, *args, **kw)
# DISPATCH_METHOD
    518         return func
    519

C:\Python26\lib\site-packages\comtypes\automation.pyc in Invoke(self, dispid, *a
rgs, **kw)
    699
    700             for i, a in enumerate(args[::-1]):
--> 701                 array[i].value = a
    702
    703             dp = DISPPARAMS()

C:\Python26\lib\site-packages\comtypes\automation.pyc in _set_value(self, value)

    298             self._.VT_R4 = value
    299         else:
--> 300             raise TypeError("Cannot put %r in VARIANT" % value)
    301         # buffer ->  SAFEARRAY of VT_UI1 ?

    302

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
David Naylor | 22 Sep 13:56
Picon

Windows 7 + amd64

Hi,

I'm trying to run comtypes under Windows 7 64bit.  When using comtypes with 
python 64bit then the script fails with:

# python excelmoniter.py
Activating excel link...
Traceback (most recent call last):
  File "excelmoniter.py", line 80, in <module>
    main()
  File "excelmoniter.py", line 68, in main
    xl = get_excel()
  File "excelmoniter.py", line 35, in get_excel
    return GetActiveObject("Excel.Application")
  File "C:\Python26\lib\site-packages\comtypes\client\__init__.py", line 180, 
in
 GetActiveObject
    obj = comtypes.GetActiveObject(clsid, interface=interface)
  File "C:\Python26\lib\site-packages\comtypes\__init__.py", line 1165, in 
GetAc
tiveObject
    oledll.oleaut32.GetActiveObject(byref(clsid), None, byref(p))
  File "_ctypes/callproc.c", line 925, in GetResult
WindowsError: [Error -2147221021] Operation unavailable

This works when using python 32bit.  

See attached for the script.  

Regards,

David
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
comtypes-users mailing list
comtypes-users@...
https://lists.sourceforge.net/lists/listinfo/comtypes-users
David Naylor | 21 Sep 12:34
Picon

Fwd: Using multiple instances of Excel

Hi,

I'm trying to use multiple instances of Excel with comtypes.  Ideally I would 
like to:
 - iterate over all active instances of Excel
 - get a Workbook using its (prior) known name (the Workbook would have been 
opened in one of the excel instances).  

Unfortunately CreateObject creates a new instance of Excel and GetActiveObject 
returns the first instance of Excel, which invariably does not have the 
required workbook.  

My searches for a solution came up with BindToMoniker which will allow me to 
get a workbook (solves the second problem) but I cannot figure out how to get 
that to work in comtypes.  

Please help.

David
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
comtypes-users mailing list
comtypes-users@...
https://lists.sourceforge.net/lists/listinfo/comtypes-users
JimG | 24 Aug 19:36
Picon
Gravatar

Blog post with Documentation links about Comtypes

I have posted a Blog post based on my experiences with Comtypes.


Hope someone finds it useful! If there are additional links then I'd be pleased to add them to the post.

There is a brilliant message in the mailing archive I can't find where Thomas Heller describes how the type stuff in automation.py works. If anyone has a link to that it would be great!

Many thanks, Jim.
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
comtypes-users mailing list
comtypes-users@...
https://lists.sourceforge.net/lists/listinfo/comtypes-users
Sathish S | 18 Aug 07:51

Using LabVIEW COM with Python

Hi All,


I'm trying to call LabVIEW VI's from python. I'm using comtypes to invoke the LabVIEW ActiveX. While using this I'm trying to pass data to a 'Call' method in 'VirtualInstrument' class of this ActiveX. I'm able to pass all types of data. Except a 2D array. I get the following error when I try to pass a 2D array.

 VirtualInstrument.Call(ParameterNames,Parameters)
  File "C:\Python27\lib\site-packages\comtypes\__init__.py", line 517, in func
    return self.Invoke(obj, memid, _invkind=1, *args, **kw) # DISPATCH_METHOD
  File "C:\Python27\lib\site-packages\comtypes\automation.py", line 717, in Invoke
    raise COMError(hresult, text, details)
COMError: (-2147352567, 'Exception occurred.', (None, None, None, 0L, -2147352571))
This COM error means Type Mismatch.

When I tried using Pywin I faced the same issue with a cluster(structure) of clusters(structures) having same number of elements. As in the attachment cluster.jpg 
Like [[1,2,3],[4,5,6]]
where [1,2,3] is one cluster and [4,5,6] is another cluster
But I was able to pass the data to 2D array in Pywin. Using comtypes I'm able to pass data to the custer of cluster data type but I'm facing issues with 2D array.

Here is my code:
from ctypes import *
import comtypes.client
omtypes.CoInitialize()
TypeLibPath = "C:\\LabVIEW Run Time Engine ActiveX Server\ActiveX Server\LVRTS.tlb"
comtypes.client.GetModule(TypeLibPath)

try:
    Application = comtypes.client.CreateObject("LabVIEWRTS.Application", None, None, comtypes.gen.LabVIEWRTS._Application)
    #VI Path
    VIPath="C:\Passing Array Data.vi"
    
    #Parameters
    Input_1=[[1,2,3],[4,5,6]]
    Input_2=[[1,2,3],[4,5,6]]
    ParameterNames=("Input 1","Input 2")
    Parameters=[Input_1, Input_2,]
    
    #Get VI Reference
    VirtualInstrument = Application.GetVIReference(VIPath)
    
    #Call VI
    VirtualInstrument.Call(ParameterNames,Parameters)
     ....
     ....
     ....

Thanks,
Sathish
------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
comtypes-users mailing list
comtypes-users@...
https://lists.sourceforge.net/lists/listinfo/comtypes-users
Dean Pavlekovic | 4 Aug 10:30
Picon

Skipped methods in tlbparser.Parser.ParseDispatch

Hello,

First, hats off to comtypes, and ctypes which is such a great addition
to Python's stdlib!

I just recently started playing with comtypes trying to automate
processing of some data sets in Excel-Access-Matlab combination.

I noticed that there are some missing methods in generated interface
for Matlab automation server component. If I use CreateObject() with
dynamic=True everything works fine though.

The problem seems to be in tlbparser.Parser.ParseDispatch() fcn where
it skips first 7 methods if first method listed is QueryInterface.
Matlab's tlb lists only the IUnknown methods (QueryInterface, AddRef,
Release), but not the IDispatch methods, so next four methods after
the 3 IUnknown methods from the interface are skipped.

There's a quick patch in attachment, I ran test_client.py,
test_excel.py and test_word.py on patched version and there were no
errors.

Cheers,
Attachment (comtypes_skip_IDispatch_methods.patch): application/octet-stream, 798 bytes
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
comtypes-users mailing list
comtypes-users@...
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Gmane