DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: CComVariant

  1. #1
    Evan Guest

    CComVariant


    I have need in my ATL COM component to pass in
    a VARIANT (at which point i assing it to a CComVariant)
    the data is nothing special..just text...it's a BSTR
    to support vbscript and vb clients. my question is this,
    after passing this in (which works) i need to convert
    the Variant to BYTE in order for a function to operate
    on it (by reference).. I have tried mVar.ChangeType(VT_BYREF|VT_UI1,NULL)
    which fails everytime..could someone show me what i'm doing
    wrong (or another way to accomplish this)

    BOOL changedata(BYTE *rawdata);

    STDMETHODIMP Cmyobj::manip(VARIANT data, VARIANT *result)
    {

    BOOL success;
    CComVariant mVar;

    mVar = data;
    if (! SUCCEEDED(mVar.ChangeType(VT_BYREF|VT_UI1,NULL))) {
    return mVar.ChangeType(VT_BYREF|VT_UI1,NULL);
    }

    success = changedata(mVar.pbVal);

    if (success) {
    mVar.Detach(result);
    return S_OK;
    }
    else {
    return E_FAIL;
    }
    }

    it always dies trying to change the variant to BYTE with a type
    mismatch error, the changedata() function operates on the function
    as a stream, and doesnt care if its text or symbols or whatever, as
    long as it is BYTE



  2. #2
    Boris Karadjov Guest

    Re: CComVariant


    "Evan" <evanh23@usa.net> wrote:
    >
    >I have need in my ATL COM component to pass in
    >a VARIANT (at which point i assing it to a CComVariant)
    >the data is nothing special..just text...it's a BSTR
    >to support vbscript and vb clients. my question is this,
    >after passing this in (which works) i need to convert
    >the Variant to BYTE in order for a function to operate
    >on it (by reference).. I have tried mVar.ChangeType(VT_BYREF|VT_UI1,NULL)
    >which fails everytime..could someone show me what i'm doing
    >wrong (or another way to accomplish this)


    If you need to operate on a single byte, convert it to VT_UI1, not VT_BYREF|VT_UI1
    and pass &V_UI1(&mVar) to your function.

    If, on the other hand, you need to manipulate the whole string as an array
    of bytes, simply cast it to (BYTE *) and pass SysStringLen(V_BSTR(&mVar))
    * sizeof(OLECHAR) as the number of bytes.


    Boris Karadjov
    Brainbench MVP for Visual C++
    http://www.brainbench.com

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links