请大家帮忙看看。谢谢!
vc_cn 2002-10-30 11:43:18 我想做一ocx供vb调用,里面有个对外函数(用来传入sql语句,传出纪录集)。这样的函数该怎么定义呢?!
//-------------内部函数大致如下:---------------
_RecordsetPtr CConnDB::GetRS(CString sqlstr)
{
_RecordsetPtr m_pRecordset("ADODB.Recordset");
_bstr_t bstrQuery(sqlstr);
HRESULT hr;
if (ConnSQL()) //这个是连接库用的函数,会得到m_pConnection
{
try
{ hr=m_pRecordset->Open(bstrQuery,_variant_t((IDispatch*)m_pConnection,true),adOpenDynamic,adLockPessimistic,-1);
}
catch(_com_error &e)
{
return NULL;
}
}
return m_pRecordset; //返回这个?!
}
以上函数,我在内部调用它,可以得到记录集。
//-----------然后,我的对外函数定义如下-----------------
LPUNKNOWN CJLCommFunCtrl::ConnGetRS(LPCTSTR sqlstr)
{
CConnDB conn;
return conn.GetRS((CString)sqlstr);
}
请问能这么返回值么?该怎么做才能返回记录集呢?
调用ocx的该方法时,程序出错了。