Re: How to Pass a SafeArray of UDT's as VARIANT

From: Alexander Nickolov (agnickolov_at_mvps.org)
Date: 12/14/04


Date: Tue, 14 Dec 2004 09:35:48 -0800

Check if your UDT is output in the generated type library.
I suspect it's not. Therefore, you need to write a little IDL
to define it there, build the type library out of it, then use it
within VB. Note, VB's UDTs are by default private.

Also, see this FAQ article:

http://www.mvps.org/vcfaq/com/4.htm

-- 
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"BigFish" <BigFish@newsgroup.nospam> wrote in message 
news:O4zA8j63EHA.2316@TK2MSFTNGP15.phx.gbl...
>I want to pass a safearray of UDT's as VARIANT so the safearray can be an
> optional parameter when passed from VB. When my method is called with no
> parameter, I get a VARIANT with vt = VT_ERROR / DISP_E_PARAMNOTFOUND which
> is correct. But when I pass with a safearray of UDT's I get vt = VT_ARRAY 
> |
> VT_BYREF | VT_VOID and my safearray is wacked. The UDT has long's and 
> BSTR's
> and the number of elements in the safearray can vary depending upon the
> number of data points in a given sample. I think my IDL is wrong. Anybody
> know how to do this?
>
> My IDL:
> [id(15), helpstring("method doProcess")] HRESULT doProcess([in, optional]
> VARIANT* pVArray);
>
> My VB:
> Dim ProcessData(0 To 2) As myObject.UDTVar
> ProcessData(0).Pressure = 10
> ProcessData(0).Location = "Southside Facility"
> etc...
> 'safearray passed
> myObject.doProcess ProcessData
>
> ends up with vt = VT_ARRAY | VT_BYREF | VT_VOID and my safearray is wacked
>
> 'and for no parameter:
> myObject.doProcess
>
> ends up with vt = VT_ERROR which is correct
>
> 


Relevant Pages

  • How to Pass a SafeArray of UDTs as VARIANT
    ... I want to pass a safearray of UDT's as VARIANT so the safearray can be an ... optional parameter when passed from VB. ... I think my IDL is wrong. ...
    (microsoft.public.vc.atl)
  • Re: Byte Array aus C++ DLL in VB importieren
    ... deklarierter Parameter in COM legal ist, ... So, wie es eben dort steht, ist der nackte Pointer ein Pointer auf ein einziges Element. ... Oder in IDL gesprochen: SAFEARRAY* ... Für den Trick mit dem (SAFEARRAY (byte) * ppsa) in der IDL ...
    (microsoft.public.de.vb)
  • Re: Problem with SAFEARRAY as property accessors.
    ... > could you plz tell me how to define these properties in .cpp file ... A SAFEARRAY(Whatever) parameter in IDL becomes SAFEARRAY* in C++. ... C++ you always specify one extra level of indirection compared to IDL ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Problem with SAFEARRAY as property accessors.
    ... > could you plz tell me how to define these properties in .cpp file ... A SAFEARRAY(Whatever) parameter in IDL becomes SAFEARRAY* in C++. ... C++ you always specify one extra level of indirection compared to IDL ...
    (microsoft.public.vc.atl)
  • Re: Marshalling a SAFEARRAY from an ATL component into CS.
    ... You should indicate the type of SAFEARRAY element, so your IDL should look ... >> Please post your method declaration. ... >>> returns a SAFEARRAY of INTs, but my C# component chokes on it. ...
    (microsoft.public.dotnet.languages.csharp)