Re: Reading a byte array from a Variant
The first works just fine, you got its signature wrong. It does
not use VARIANT - it uses _variant_t. So if you stored the
returned value into a VARIANT, it got destroyed on the same
line since it's a temporary. Simply changing your variable to be
of type _variant_t should make it work (don't forget to remove
its cleanup code as cleanup is handled in the class destructor).
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Jeff Robichaud" <jfrobichaud@gmail.com> wrote in message
news:e%23exmaneGHA.4912@TK2MSFTNGP05.phx.gbl...
Well I have finally been able to work this out. When importing a typelib
in VC without the raw_interfaces_only attribute, you get 2 versions of
every function, one low-level version (usually prefixed with "raw_") and
one error-handling version. The 2 don't have the same signature, for
example if I have this in IDL:
HRESULT GetArrayObject([in] VARIANT byteArray, [out, retval] VARIANT*
pRetVal);
I get the 2 following versions:
VARIANT GetArrayObject(VARIANT& byteArray);
AND
HRESULT raw_GetArrayObject(VARIANT byteArray, VARIANT* pRetVal);
From the start I was using the first version, which yields the results I
have seen so far, but the second one works. It requires me to declare de
VARIANT locally and pass a pointer to get the return value.
Can you explain why the first version doesn't work ?
"Vi2" <sharachov@hotmail.com> a ?crit dans le message de news:
1147922388.829581.247100@g10g2000cwb.googlegroups.com...
Possible reason is the VB (VB6) returns the variable which name is
equal to the function name:
Public Function GetArray(ByRef b() As Byte) As Byte()
GetArray = b
End Function
Otherwise the function returns the empty array, which has the right
type, but doesn't contain any value. I.e. vaRet.vt will be (VT_ARRAY |
VT_UI1), but vaRet.parray will be NULL.