[python-win32] What is Variant VT_UI1 in Python?

Mark Hammond mhammond at skippinet.com.au
Tue Oct 17 04:17:09 CEST 2006


> Hello,
>
> I'm having difficulty passing a VT_UI1 to a COM
> object. I've tried passing a list/tuple of bytes but
> it's raising an exception. When I pass a buffer, there
> is no exception but the returned IAutoLogPacket is
> None. What is "an array of bytes"?
>
> Here is the makepy generated method (I'm certain I'm
> using early bound dispatch):
>
> 	# Result is of type IAutoLogPacket
> 	def ProcessPacket(self,
> packet=defaultNamedNotOptArg):
> 		"""packet is an array of bytes"""
> 		ret = self._oleobj_.InvokeTypes(32, LCID, 1, (9, 0),
> ((12, 1),),packet
> 			)
> 		if ret is not None:
> 			ret = Dispatch(ret, 'ProcessPacket',
> '{568A44F9-6FB2-4814-8195-BCF6F1409288}',
> UnicodeToString=0)
> 		return ret

The function is declared as taking a simple variant.  This means that
explicitly passing a buffer object should work - eg, buffer('foo\0bar'), for
example.  (If it was explicitly declared as a VT_ARRAY | VT_UI8, passing a
simple string would work too)

I just made a change to the win32com test suite to confirm this.  testvb.py
was changed to include:

    vbtest.VariantProperty = buffer('raw\0data')
    if str(vbtest.VariantProperty) != 'raw\0data':
        raise error, "Could not set the variant buffer property correctly."

This is similar to your example (although a property is being used instead
of an arg to a method.)  After setting the property to the buffer,
re-reading the value results in an object '<read-write buffer ptr
0x00C5C7C0, size 8 at 0x00C5C7A0>' - hence the conversion to string before
the comparison.  However, this demonstrates to me that VT_UI1 support in
variants is working fine.

Probably the best way forward is to try and reproduce your problem in the
win32com test suite...

Hope this helps,

Mark



More information about the Python-win32 mailing list