using a com automation object (how do I avoid crash?)

Simon Brunning simon.brunning at gmail.com
Thu May 26 04:59:55 EDT 2005


On 5/25/05, James Carroll <mrmaple at gmail.com> wrote:
> I'm trying to call functions on an automation object, and I've run
> makepy to generate a wrapper, and 99% of the calls I make on the
> wrapper work great.
> 
> my question is: Is my [''] * 10  as close as I can come to a variant
> array of pre-allocated empty strings?
> 
> I'm trying to call a function called EnumerateCameras
> 
> m.ShowLiveWindow(True)    <--- this works
> cams = [''] * 10
> m.EnumerateCameras(cams)
> <CRASH!>

Python strings are immutable. If EnumerateCameras is trying to modify
them, who knows *what* might happen...

> Is my [''] * 10  as close as I can come to a variant array of
> pre-allocated empty strings?

Have you looked at ctypes?
(<http://starship.python.net/crew/theller/ctypes/>.) It has a
create_string_buffer function for creating mutable memory blocks, so
you might do somethign like:

cams = list(ctypes.create_string_buffer(256) for _ in range(10))

256 is a wild guess, obviously. ;-)

-- 
Cheers,
Simon B,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/



More information about the Python-list mailing list