发博文
正文 字体大小:

各种字符串类型三(CComBSTR)

(2008-07-07 09:17:25)
标签:

it

三.CComBSTR

1.构造函数(看以下的代码即可)

          CComBSTR bstrPre("Hello ");

 

   // Appends "Wo" to "Hello " (4 bytes == 2 characters)

   bstrPre.AppendBytes( reinterpret_cast(L"World!"), 4 );

 

   // Displays a message box with text "Hello Wo"

   ::MessageBox(NULL, CW2CT(bstrPre), NULL, MB_OK);

 

   CComBSTR bstr1;    // BSTR points to NULL

   bstr1 = "Bye";     // initialize with assignment operator

 

   OLECHAR* str = OLESTR("ta ta");   // wide char string of length 5

   CComBSTR bstr2(wcslen(str));      // unintialized BSTR of length 5

   wcscpy(bstr2.m_str, str);         // copy wide char string to BSTR

 

   CComBSTR bstr3(5, OLESTR("Hello World")); // BSTR containing 'Hello',

                                               // input string is wide char

   CComBSTR bstr4(5, "Hello World");          // same as above, input string

                                               // is ANSI

 

   CComBSTR bstr5(OLESTR("Hey there")); // BSTR containing 'Hey there',

                                          // input string is wide char

   CComBSTR bstr6("Hey there");          // same as above, input string

                                          // is ANSI

 

   CComBSTR bstr7(bstr6);      // copy constructor, bstr7 contains 'Hey there'

 

2. HRESULT AppendBSTR(BSTR p ) throw( ); //将p附加到CComBSTR后面(字符串相加)

3. HRESULT AppendBytes(const char* lpsz,int nLen) throw( ); //同上,ANSI版

4. void Attach(BSTR src ) throw( ); //同_bstr_t中的

5. BSTR m_str; //这是属性,是与CComBSTR关联的BSTR

6.Length()://返回m_str的长度

7.Empty()://释放m_str

8. Detach()://同_bstr_t

9. ByteLength()返回m_str的字节数

10. BSTR Copy( ): //返回m_str的一个BSTR副本

11. HRESULT CopyTo(BSTR* pbstr ) throw( );

HRESULT CopyTo(VARIANT* pvarDest ) throw( );

//拷贝m_str的一个副本到所提供的地址中

12. ToLower()://将m_str转化为小写的

13. ToUpper()://将m_str转化为大写怕

14. HRESULT BSTRToArray(LPSAFEARRAY* ppArray ) throw( );

//将m_str拷贝到ppArray的安全数组中

阅读 评论 收藏 转载 打印举报
已投稿到:
  • 评论加载中,请稍候...

       

    验证码: 请点击后输入验证码 收听验证码

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 不良信息反馈 电话:4006900000 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有