Re: Reading a byte array from a Variant

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Oh, exactly...I didn't notice I had the wrong type since the code would
compile OK. Thanks a lot!

"Alexander Nickolov" <agnickolov@xxxxxxxx> a écrit dans le message de news:
u%23Kpn6peGHA.3640@xxxxxxxxxxxxxxxxxxxxxxx
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@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

"Jeff Robichaud" <jfrobichaud@xxxxxxxxx> wrote in message
news:e%23exmaneGHA.4912@xxxxxxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxxx> a écrit dans le message de news:
1147922388.829581.247100@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.







.



Relevant Pages

  • Re: ATL generates bad code for Firing events with [out] arguments
    ... This is not a bug, ... VT_PI4 is not a valid vartype for a VARIANT. ... "DavidB" wrote in message ... >> Microsoft MVP, MCSD ...
    (microsoft.public.win32.programmer.ole)
  • Re: How to casting to VARIANT*
    ... Microsoft MVP, MCSD ... but I wonder why MSWORD is designed this way. ... > in there that just take a plain VARIANT. ... > optional are also passed by pointer. ...
    (microsoft.public.vc.atl)
  • Re: Extracting Data in C++ VARIANT that was created by VB
    ... > learning exercise I am trying using a VARIANT instead and this is where I ... > "Alexander Nickolov" wrote in message ... >> Microsoft MVP, MCSD ...
    (microsoft.public.vc.atl)
  • Re: optional Safearray of UDTs from VB
    ... > phEngine.DoProcess InstMeasure 'VB ARRAY / safearray parameter ... > "Alexander Nickolov" wrote in message ... >> I think I already told you to use a VARIANT, ... >> Microsoft MVP, MCSD ...
    (microsoft.public.vc.atl)
  • Re: Extracting data from a VARIANT
    ... Microsoft MVP, MCSD ... > VARIANT, it has a vt of VT_ARRAY | VT_DISPATCH and the ... > Dim rstReadData As ADODB.Recordset ... > from the recordset to my extractor function ...
    (microsoft.public.vc.atl)