Getting a ValueError with comtypes

winkatl1213 at yahoo.com winkatl1213 at yahoo.com
Thu Oct 5 10:25:59 EDT 2006


Hello,

I am working with comtypes to interface Microsoft's DirectShow library.

First, I found a Type Library on the internet that was created for
accessing DirectShow from .NET.  It seems that DirectShow only comes
with IDL files and no type library.

This got me started.

The following line imports the typelibrary and automatically generates
a wrapper module for DirectShow.

ds = comtypes.client.GetModule('DirectShow.tlb')

Next, I can basically start with something like this:

graph = comtypes.CoCreateInstance(CLSID_FilterGraph, ds.IGraphBuilder,
comtypes.CLSCTX_INPROC_SERVER)

I had to create the CLSID_FilterGraph parameter myself by doing the
following:

CLSID_FilterGraph =
comtypes.GUID('{e436ebb3-524f-11ce-9f53-0020af0ba770}')

One of the first issues I ran into was that the type library I found on
the web didn't expose the IMediaControl interface.  So, using the
generated wrapper as a template, I created my own wrapper:

class IMediaControl(comtypes.IUnknown):
    _case_insensitive_ = True
    _iid_ = comtypes.GUID('{56A868B1-0AD4-11CE-B03A-0020AF0BA770}')
    _idlflags_ = []
IMediaControl._methods_ = [
    COMMETHOD([], HRESULT, 'Run'),
    COMMETHOD([], HRESULT, 'Pause'),
    COMMETHOD([], HRESULT, 'Stop'),
    COMMETHOD([], HRESULT, 'StopWhenReady'),
    COMMETHOD([], HRESULT, 'GetState',
              (['in'], c_long, 'msTimeout'),
              (['out'], POINTER(c_int), 'pfs' ))
]

This got me further.  Once I defined the interface, I get access to the
interface by calling:

control = graph.QueryInterface(IMediaControl)

This seemed to work.  Once I got everything setup, I tried to use this
interface.  For example:

control.Run()

This generates an exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "ds.py", line 462, in play
    control.Run()
ValueError: Procedure probably called with not enough arguments (4
bytes missing)

You can get errors like this when using ctypes if you use the wrong
calling convention (CDLL versus WINDLL).

The method "Run" on the IMediaControl interface doesn't take any
arguments.

I did notice that some wrapper code uses STDMETHOD versus COMMETHOD,
but changing this didn't make any difference.

Can anyone explain what might be happening here, or offer some
suggestions?

Thanks in advance,

Jeff




More information about the Python-list mailing list