Getting a ValueError with comtypes

Thomas Heller theller at python.net
Thu Oct 5 14:07:13 EDT 2006


winkatl1213 at yahoo.com schrieb:
> Thomas,
> 
> Thanks a ton for the quick response.
> 
> I called GetModule('quartz.dll'), and now I can at least call
> IMediaControl::Run.  I get another error, but that's my problem (I
> don't have the graph set correctly yet).
> 
> You mentioned that you sometimes create a type library for creating the
> interface wrappers.
> 
> Would you mind sharing with me how you do this?

Nothing fancy: I compile them with midl.

> I seem to recall a thread on ctypes-users where you were looking for a
> method to do this.  I can't seem to locate what you conclusion was.
> 
> By the way, I've been using ctypes and comtypes quite a bit lately, and
> I just wanted to say that they are both excellent.

Thanks!

> Now if only I had an equivalent way to access C++ dlls, I'd no longer
> have to write typemaps in SWIG.
> 
> While I'm at it, I thought I would ask you a separate completely
> unrelated question.
> 
> I have a C++ library wrapped with SWIG.  One member function takes a
> void* to a buffer.
> 
> I want to allocate this buffer using ctypes and pass it to my SWIG
> wrapper, but I've been struggling to get it to work.
> 
> I tried passing in the addressof, and then casting it back in my SWIG
> wrapper, but this doesn't work.  Do you have any suggestions on this?

Which object does the SWIG wrapper expect?  Would a bufferobject suffice?
If this is the case, you could call buffer() on a ctypes object, maybe one
created with 'ctypes.create_string_buffer(size_in_bytes)'.  Every ctypes
type instance supports the buffer protocol.

> I've also thought about using a numpy array, since this is supported in
> both SWIG and ctypes.

That might also work.

Thomas




More information about the Python-list mailing list