zoukankan      html  css  js  c++  java
  • 【转】Converting char array to BSTR

    转自:http://forums.devx.com/archive/index.php/t-86391.html

    ---------------------------------------------------------------------1楼------------------------------------------------------------------------

    How can I convert a char array to a BSTR variable?

    I have tried using the SysAllocString() function and the syntax is correct.
    However, when I call the function from VB I get a GPF.

    Here is an example

    void __stdcall TestStr ( BSTR var1)
    {
    char var2[50];

    // pass the pointer to the char array.
    var1 = SysAllocString(*var2)
    }


    any input would be appriciated.

    Chris
    zak
    08-17-2000, 04:42 AM

    ---------------------------------------------------------------------2楼 ------------------------------------------------------------------------

    Hi chris,


    Here is an example that show how to convert an array of char to a BSTR:

    void __stdcall TestStr(BSTR bstr)
    {
    CComBSTR str(OLESTR(
    "My name is prince and I am funky"));
    bstr 
    = str.Detach();
    }


    That is all you need to do to convert an array of char to a BSTR.
    Don't forget to use CComBSTR. It is a smart BSTR class and so deals with
    all the intracacies of BSTR that we mere programers we forget to follow.


    There is an iteresting discussion about CComBSTR in the 'ATL Internals' written
    by brent rector and chris sells.
     
  • 相关阅读:
    企业IT管理说:全自动就一定是最好的吗?
    银行爱“IOE”爱得有多深
    谷歌数据中心
    屏蔽爬虫
    ,net运行框架
    视频格式
    HTTP协议
    IE的体系和webrowser
    jsp请求由servlet响应的方式
    Web请求响应简单整理
  • 原文地址:https://www.cnblogs.com/fzzl/p/2151446.html
Copyright © 2011-2022 走看看