COM: Passing arrays, SAFEARRAYs, and BSTRs in connection points

Mark Hammond mhammond at skippinet.com.au
Wed Mar 22 18:44:48 EST 2000


In article <38d8e3f2$0$2941 at senator-bedfellow.mit.edu>,
"Robert" <soundhack at hotmail.com> wrote:
> The short form of the question:
> pythoncom seems to convert BSTR/unicode strings to normal python
strings
> automatically. Is there any way of recovering the original raw data?
> I am sending raw chars that are converted to BSTRs through COM to
> a python program. For example I am sending 'test' (4 bytes) in a
> SAFEARRAY/vector,
> convert it to a bstr using BstrFromVector, then send it off to
python, which
> somehow converts it to a string '??' (2 bytes). Is there anyway of
> retrieving the
> original 4 bytes?

You should be using a safe array of type VT_UI1 - this is the type that
most objects (eg, MS Database objects, etc) use for binary data.

When Python recieves a variant of this type, the Python program sees
the 4 bytes returned in a "buffer" object.

If you need to pass a 4 byte buffer to an external COM object from
Python, then you use the buffer built-in - eg:

CallSometing(buffer("test"))

Will cause Python to create a VT_UI1 safearray with the 4 bytes.

Looking at your "long story", it appears you are attempting to do this -
 we only added this feature since 125, so if you are not in 128 then
upgrade, and it should work.  If you _are_ on 128, mail me and we can
sort it out.

Mark.


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list