Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 654545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:30:22+00:00 2026-05-13T22:30:22+00:00

Are there any easy-to-use , high-level classes or libraries that let you interact with

  • 0

Are there any easy-to-use, high-level classes or libraries that let you interact with VARIANTs in Visual C++?

More specifically, I’d like to convert between POD types (e.g. double, long), strings (e.g. CString), and containers (e.g. std::vector) and VARIANTs. For example:

long val = 42;
VARIANT var;
if (ToVariant(val, var)) ...     // tries to convert long -> VARIANT
comObjPtr->someFunc(var);

std::vector<double> vec;
VARIANT var = comObjPtr->otherFunc();
if (FromVariant(var, vec)) ...   // tries VARIANT -> std::vector<double>

I (naively?) assumed that people working with COM do this all the time, so there would most likely be a single convenient library that handles all sorts of conversions. But all that I’ve been able to find is a motley assortment of wrapper classes that each convert a few types:

  • _variant_t or CComVariant for POD types
  • _bstr_t, CComBSTR, or BSTR for strings
  • CComSafeArray or SAFEARRAY for arrays

Is there any simple way — short of switching to Visual Basic — to avoid this nightmare of awkward memory management and bitwise VT_ARRAY | VT_I4 code?

Related questions:

  • CComVariant vs. _variant_t, CComBSTR vs. _bstr_t
  • Convert VARIANT to…?
  • How to best convert VARIANT_BOOL to C++ bool?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:30:22+00:00Added an answer on May 13, 2026 at 10:30 pm

    Well, most of the hard work is already done for you with the various wrapper classes. I prefer _variant_t and _bstr_t as they are more suited for conversion to/from POD types and strings. For simple arrays, all you really need is template conversion function. Something like the following:

    // parameter validation and error checking omitted for clarity
    template<typename T>
    void FromVariant(VARIANT Var, std::vector<T>& Vec)
    {
        CComSafeArray<T> SafeArray;
        SafeArray.Attach(Var.parray);
        ULONG Count = SafeArray.GetCount();
        Vec.resize(Count);
        for(ULONG Index = 0; Index < Count; Index++)
        {
            Vec[Index] = SafeArray[Index];
        }
    }
    ....
    std::vector<double> Vec;
    VARIANT Var = ...;
    FromVariant(Var, Vec);
    ...
    

    Of course things get hairy (in regards to memory / lifetime management) if the array contains non-POD types, but it is still doable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any easy to use python components that could be used in a
Is there any easy way to tell perl now ignore everything that is printed?
Is there any easy to use PHP Security Scanner?
I was wondering if there is any easy tool to use in order to
Is there any easy way to use grep functionality in NSIS scripts? I have
Is there any easy way to use the UIButton icons (UIButtonTypeInfoLight) on a UIBarButton
I'm wondering there is any easy way to use masks/cliping with openGL in objective
I'm interested in developing J2ME applications for mobile. Is there any easy-to-use, free software
Are there any good and easy to use ruby task schedulers? I just need
Is there any easy library or approach to get the week (from which date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.