CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 26

Threaded View

  1. #7
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: COleVariant in WinAPI (afxdisp.h)

    Quote Originally Posted by VictorN View Post
    Try to change your code to be:
    Code:
    VARIANT xx;
    xx.vt=VT_BSTR;
    xx.pcVal= L"a1";
    this doesn't create a proper VARIANT to a BSTR, even if you fixed it to set it to bstrVal instead of pcVal.
    it creates a variant of type VT_BSTR with the BSTR part pointing to a static wide character string. Wide char string != BSTR.

    Depending on how the receiving function works. This can either work without any form of issue, or it can have all kinds of failures.

    BSTR's are BSTR's, they are NOT simply pointers to any type of wide character strings.



    The above would be correct if you used a VT_LPWSTR type, but not everything accepting a VARIANT will handle that type properly (a lot don't).
    If you pass a VT_BSTR, make sure you have an actual BSTR, meaning, it should be allocated via SysAllocString() or it should be NULL indicating an empty string (not a NULL string). There are C++ wrapper classes such as CComBSTR (ATL/MFC) and _bstr_t (compiler COM support) to help you manage BSTR's.
    Last edited by OReubens; May 27th, 2013 at 07:44 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured