convert char** to BSTR

Posted on 2008-11-06
Last Modified: 2012-06-27
how to convert char** to BSTR
Question by:Sohela
    LVL 30

    Accepted Solution

    Hi Sohela,

    there's a function 'BSTR SysAllocString( const OLECHAR *sz );' which can be used for this.

    To use it you need a OLECHAR* - to convert a 'char*' to 'const OLECHAR*' you can use the macro 'A2COLE'

    So, if you have a 'char** pChar' (which is a pointer to a pointer of chars) it should be possible to do it like this:

    const OLECHAR* pOleChar = A2COLE( *pChar );
    BSTR str = SysAllocString( pOleChar );
    // do something with the 'str'
    SysFreeString( str ); // need to cleanup the allocated BSTR

    Hope that helps,


    Author Comment

    hey thanks a lot got it
    LVL 30

    Expert Comment

    Fine, that's great.
    LVL 14

    Expert Comment

    You could also use one of the BSTR wrapper classes such as CComBSTR or _bstr_t, both of which can take a char* in the constructor:

    char ** ppChar;


    CComBSTR myComBSTR(*ppChar);

    _bstr_t my_bstr_t(*ppChar);

    Then you get all of the other functionality of the classes, including the ability to detach the underlying BSTR if you need it.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    matchUp  challenge 9 50
    scoresSpecial  challenge 13 34
    Python 2.7 - French characters 6 29
    wordmultiple challenge 12 63
    Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
    There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now