I may be saved.  I'm still not sure exactly why, though.

After some desperate tracing, I found something that works ( I found an 'if'
statement when calling the method which always went down one path when I
passed in an LP_LP_c_double instance.  I forced it down the other path by
passing in an instance of LP_SAFEARRAY_c_double, as shown below):

>>> import ctypes
>>> import comtypes.safearray as safearray
>>> safearray
<module 'comtypes.safearray' from
'C:\Python25\lib\site-packages\comtypes\safearray.pyc'>

>>> itrace = bench.SA.Traces[u'Trace1']
>>> itrace
<POINTER(IIviSpecAnTrace) ptr=0x2216610 at 107a8a0>

>>> AmplitudeType = safearray._midlSAFEARRAY(ctypes.c_double)
>>> AmplitudeType
<class 'ctypes.LP_SAFEARRAY_c_double'>
>>> amplitude = AmplitudeType()

>>> amplitude
<ctypes.LP_SAFEARRAY_c_double object at 0x00FB3DF0>
>>> itrace.FetchY(amplitude)
<ctypes.LP_SAFEARRAY_c_double object at 0x00FB3DF0>

and amplitude.unpack() gives me what I was looking for all along.  I've
actually found several different routes to the same end, as well, using the
underlying SafeArray* functions in oleaut32.dll and the ctypes structures
tagSAFEARRAYBOUNDS and tagSAFEARRAY and fun with cast, from_address, and
address of.  I actually learned a lot doing this.

After much digging into pointers and arrays in ctypes, one question remains
for me (and I have just checked out the ctypes trunk to try to figure this
out myself) is what the mechanics of classes defined as POINTER(
<COM_interface_class> ) work.  That is, there's no contents attribute
(something I looked at briefly, again in desperation, to get access to the
wrapped COM interface), they can't be indexed, so on and so forth.  I figure
this must be an interaction of the _Pointer class, from which types
constructed with POINTER inherit, and the metaclass of COM interface
classes.  Any commentary is welcome.

Man, I love this module.

Matt



On Sat, May 10, 2008 at 3:05 PM, <
[EMAIL PROTECTED]> wrote:

> Send comtypes-users mailing list submissions to
>        comtypes-users@lists.sourceforge.net
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        https://lists.sourceforge.net/lists/listinfo/comtypes-users
> or, via email, send a message with subject or body 'help' to
>        [EMAIL PROTECTED]
>
> You can reach the person managing the list at
>        [EMAIL PROTECTED]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of comtypes-users digest..."
>
>
> Today's Topics:
>
>   1. SAFEARRAY SNAFU (Matt Wilbur)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 9 May 2008 16:26:42 -0400
> From: "Matt Wilbur" <[EMAIL PROTECTED]>
> Subject: [comtypes-users] SAFEARRAY SNAFU
> To: comtypes-users@lists.sourceforge.net
> Message-ID:
>        <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hello All, especially Thomas,
>
> I'm running into a fairly serious snag calling a method that is supposed
> to
> take a SAFEARRAY** as input.  The class generated from GetModule is
>
> IIviSpecAnTrace._methods_ = [
>    COMMETHOD([helpstring(u'This function returns the trace the spectrum
> analyzer aquires.')], HRESULT, 'FetchY',
>              ( ['in', 'out'], POINTER(_midlSAFEARRAY(c_double)),
> 'Amplitude' )),
>
> <other methods omitted>
>
> ]
>
>
> >From the header file its:
>
>   public:
>        virtual /* [helpcontext][helpstring] */ HRESULT STDMETHODCALLTYPE
> FetchY(
>            /* [out][in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *Amplitude) =
> 0;
>
>
>
> Everything was going swimmingly until I tried to use this function.
>  Here's
> what I do:
>
> In [305]: safe2 = (c_double*401)()
>
> In [306]: safe2
> Out[306]: <__main__.c_double_Array_401 object at 0x0292A670>
>
> I tried manually creating the SAFEARRAY and passing it to the FetchY
> method,
> but I got bounced because it looked like the underlying Python code was
> constructing it for me.
>
> However, the array, when returned, is filled with 0.0.  In fact, whatever
> I
> fill the array with, it remains unchanged after the call.
>
> I've verified things work correctly at the C++ level, and I've verified
> the
> instrument is communicating and sending back the right values.  I'm
> obviously buggering something up, but after a day and a half of
> investigation, I have to admit I'm stumped.  I don't know enough about the
> internals of comtypes to debug this, so I'm hoping Thomas can help me out.
>
> Matt
> -------------- next part --------------
> An HTML attachment was scrubbed...
>
> ------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
>
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>
> ------------------------------
>
> _______________________________________________
> comtypes-users mailing list
> comtypes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/comtypes-users
>
>
> End of comtypes-users Digest, Vol 9, Issue 2
> ********************************************
>
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to