DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Passing Variant data type from a COM DLL to a VB

  1. #1
    Grace Guest

    Passing Variant data type from a COM DLL to a VB


    I need information on how COM encapsulation of the variant data type works.
    I am trying to pass data back to a VB program using variants and I am having
    trouble getting it to work.
    Please help if you have dealt with such a problem before.

  2. #2
    Robert Guest

    Re: Passing Variant data type from a COM DLL to a VB


    "Grace" <gfaustino@tsidef.com> wrote:
    >
    >I need information on how COM encapsulation of the variant data type works.
    >I am trying to pass data back to a VB program using variants and I am having
    >trouble getting it to work.
    >Please help if you have dealt with such a problem before.


    Here is a sample of passing a variant to a vb program using ATL COM...

    ...
    interface IName : IDispatch
    {
    [propget, id(1), helpstring("property TestName")] HRESULT TestName([out,
    retval] VARIANT *pVal);
    [propput, id(1), helpstring("property TestName")] HRESULT TestName([in]
    VARIANT newVal);
    };
    ...

    {
    ...
    public:
    STDMETHOD(get_TestName)(/*[out, retval]*/ VARIANT *pVal);
    STDMETHOD(put_TestName)(/*[in]*/ VARIANT newVal);
    private:
    BSTR sName;
    ...
    }


    STDMETHODIMP CName::get_TestName(VARIANT *pVal)
    {
    pVal->vt = VT_BSTR;
    pVal->bstrVal = sName;
    return S_OK;
    }

    STDMETHODIMP CName::put_TestName(VARIANT newVal)
    {
    newVal.vt = VT_BSTR;
    sName = newVal.bstrVal;
    return S_OK;
    }



  3. #3
    Grace Guest

    Re: Passing Variant data type from a COM DLL to a VB


    "Robert" <comknight@pdq.net> wrote:
    >
    >"Grace" <gfaustino@tsidef.com> wrote:
    >>
    >>I need information on how COM encapsulation of the variant data type works.
    >>I am trying to pass data back to a VB program using variants and I am having
    >>trouble getting it to work.
    >>Please help if you have dealt with such a problem before.

    >
    >Here is a sample of passing a variant to a vb program using ATL COM...
    >
    >...
    >interface IName : IDispatch
    >{
    > [propget, id(1), helpstring("property TestName")] HRESULT TestName([out,
    >retval] VARIANT *pVal);
    > [propput, id(1), helpstring("property TestName")] HRESULT TestName([in]
    >VARIANT newVal);
    >};
    >...
    >
    >{
    >...
    >public:
    > STDMETHOD(get_TestName)(/*[out, retval]*/ VARIANT *pVal);
    > STDMETHOD(put_TestName)(/*[in]*/ VARIANT newVal);
    >private:
    > BSTR sName;
    >...
    >}
    >
    >
    >STDMETHODIMP CName::get_TestName(VARIANT *pVal)
    >{
    > pVal->vt = VT_BSTR;
    > pVal->bstrVal = sName;
    > return S_OK;
    >}
    >
    >STDMETHODIMP CName::put_TestName(VARIANT newVal)
    >{
    > newVal.vt = VT_BSTR;
    > sName = newVal.bstrVal;
    > return S_OK;
    >}
    >
    >





    Thank you for the sample code. I finally succeeded in passing data back and
    fourth

    Grace


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center