在访问activeX时,为什么它的串是_bstr_t类型的,但是我用LPCTSTR串给它赋值也照样通过,谁能解释???

解决方案 »

  1.   

    _bstr_t是ATL提供的COM组件来支持BSTR类型的运算。使用它会自动申请和释放内存资源。BSTR是一个32位码的字符串指针,也是一组Unicode的数组,尾端以NULL Terminator结尾。不同的是他前端有一个header,用来记载字符数组的长度。
      

  2.   

    再看一个常用的数据类型:
    CComBSTR也是ATL提供的COM组件来支持BSTR类型的运算。使用它会自动申请和释放内存资源。使用方法:
    Cwindow wndobj;
    wndobj.Attach(m_ctlEdit.m_hWnd);
    CComBSTR bstr_display(“”);
    wndobj.GetWindowText(bstr_display.m_str);
    bstr_display.Append(_T(“\r\nLeft Button Click Trigger Event OnLButtonDblClk”));
    _bstr_t  display(bstr_display.m_str);
    Wndobj.SetWindowText(display);
      

  3.   

    重载了此操作符,from csdn:operator const char*( ) These operators can be used to extract raw pointers to the encapsulated Unicode or multibyte BSTR object. The operators return the pointer to the actual internal buffer, so the resulting string cannot be modified.所以他自动转换。