如何将BSTR数据类型转换到_bstr_t数据类型?

Julia 2000-09-14 04:03:00

The program of ATL COM can run succeed. But at last it shows that the executive file of this COM is runtime error and abnormal programer
termination. Then I notice that the parameter of the function shows errors CXX0030 and CXX0017. Why? The code is the following:

.........
HRESULT hr = S_OK;
long id = 123;
BSTR pwd;

//initial a BSTR varialbe
wchar_t * sss = L"abc";
SysReAllocString(&pwd,sss);
_ConnectionPtr pObjADO_Connection = NULL;

// Create ADO connection
hr = pObjADO_Connection.CreateInstance(__uuidof(Connection));
hr = pObjADO_Connection->Open(
_bstr_t L"Provider=Microsoft.Jet.OLEDB.3.51;
Data Source=E:\\ZYHU\\Test_ado\\dbCustomerPasswordC.mdb;"),
_bstr_t(L""),
_bstr_t(L""),
adModeUnknown);

// String I/O stream to write SQL statement
basic_stringstream<wchar_t> strSQLStatement;

// Write the SQL statement into a string
// Cast variant dates to bstr_t so they will be converted into a string
strSQLStatement << L"INSERT INTO Customers (CustomerID, Password) VALUES ("
<< id << L",' "
<< pwd << L"')" << ends;
bstr_t strSQLStmt = strSQLStatement.str().c_str();
_variant_t vntRecordsAffected(0L);

// Execute the SQL statement to add a record
hr = pObjADO_Connection->Execute(strSQLStmt, &vntRecordsAffected,
adOptionUnspecified);
SysFreeString(pwd);
SysFreeString(strSQLStmt);
pObjADO_Connection->Close();
.........

Besides,I want to know how I can convert a variable of the BSTR data type to a
variable of the _bstr_t data type,vice
versa. I look up the mothed in the msdn,but it doesn't work. Can you help me? Thanks.
huzhiyuan2000@sina.com
...全文
205 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Julia 2000-09-23
  • 打赏
  • 举报
回复
I'm very sorry. In ATL, it doesn't support the type CString. My ATL COM can run. But there is still many bugs.
Fideo 2000-09-19
  • 打赏
  • 举报
回复
CString str(bstr)
_bstr_t tstr(str.operaotr const char*())
WINDOWS程序设计中最常用的一些消息: 2 1 窗口消息:WM_CREATE,WM_DESTROY,WM_CLOSE 2 2 键盘消息:WM_CHAR,WM_KEYDOWN,WM_KEYUP 2 3 鼠标消息:WM_MOUSEMOVE,WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBCLICK,WM_RBUTTONDOWN, WM_RBUTTONUP,WM_RBUTTONDBCLICK 2 4 另一组窗口消息:WM_MOVE , WM_SIZE , WM_PAINT 2 5 焦点消息WM_SETFOCUS,WM_KILLFOCUS 3 6 定时器消息:WM_TIMER 3 MFC、ATL和STL 3 得到网关 4 CString最全面的总结 4 CString 拷贝 & 赋值 & "引用内存块" 什么时候释放? 4 FreeExtra()的作用 5 Format(...) 与 FormatV(...) 6 LockBuffer() 与 UnlockBuffer() 6 CString 只是处理串吗? 6 AllocSysString()与SetSysString(BSTR*) 7 参数的安全检验 7 CString的异常处理 7 跨模块时的CString.即一个DLL的接口函数中的参数为CString&时,它会发生怎样的现象。 7 串操作是编程中最常用也最基本的操作之一. 8 打开对话框选择多个文件 11 用VC设计托盘图标程序 12 一、NOTIFYICONDATA结构 12 二、Shell_NotifyIcon函数 13 三、托盘图标程序设计示例 13 VC常用数据类型使用转换详解 15 一、其它数据类型转换为字符串 15 二、从其它包含字符串的变量中获取指向该字符串的指针 16 三、字符串转换为其它数据类型 16 四、其它数据类型转换到CString 16 五、BSTR、_bstr_t与CComBSTR 16 六、VARIANT 、_variant_t 与 COleVariant 17 七、其它 18

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧