如何将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
...全文
206 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*())

3,245

社区成员

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

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