描述:
大家好,我使用了atl的mts组件向导,做了一个组件,在这个组件里,有一个接口,接口功能为由客户的卡号,可以知道客户的基本信息。在这个接口里只有一个函数GetBuCustID([in ,string]Bstr strCardNumber,[out ,retval]LPDISPACH *ppRecordset)
这个函数我是这样实现的,
STDMETHODIMP CCDataSource::GetByCustID(BSTR strCustID, LPDISPATCH *ppRecordset)
{
// TODO: Add your implementation code here
HRESULT hr=S_OK;
try
{
_ConnectionPtr pObjADO_Connection;
pObjADO_Connection.CreateInstance(__uuidof(Connection));
bstr_t strFileDSN=L"FILEDSN=lht.dsn";
hr=pObjADO_Connection->Open(strFileDSN,(BSTR)NULL,(BSTR)NULL,-1);
basic_stringstream<wchar_t> strSQLStatement;
strSQLStatement<<L"select * from table1"<<ends;
bstr_t strSQLStmt=strSQLStatement.str().c_str();
variant_t vntRecordsAffected;
_RecordsetPtr pObjADO_Recordset;
pObjADO_Recordset=pObjADO_Connection->Execute(strSQLStmt,&vntRecordsAffected,
adCmdText);
pObjADO_Recordset->QueryInterface(IID_IDispatch,(void **)ppRecordset);
}
catch(_com_error &e)
{
LPVOID lpMsgBuf;
hr=e.Error();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
FORMAT_MESSAGE_FROM_SYSTEM,NULL,hr,
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,0,NULL);
AtlReportError(CLSID_CDataSource,(LPCOLESTR)lpMsgBuf,
IID_ICDataSource,hr);
LocalFree(lpMsgBuf);
}
return hr;
}
这个组件完成了之后,我想调试一下,又建了一个mfc appwizard(exe),我建了一个对话框,在这里放上一个按钮button1,然后关于onbutton1(),又写了以下的程序
void CTestadoDlg::OnButton1()
{
HRESULT hr=S_OK;
//try{
Idb_Data1Ptr pObj;
pObj.CreateInstance(__uuidof(Idb_Data1));
wstring wstr=L"211218";
_bstr_t bstr=wstr.c_str();
//bstr=::SysAllocString(str);
_RecordsetPtr rec;
hr=pObj->GetByCustID(bstr,rec);
}
编译错误:error C2664: 'GetByCustID' : cannot convert parameter 2 from 'class _com_ptr_t<class _com_IIID<struct ADODB::_Recordset,&struct __s_GUID _GUID_00000556_0000_0010_8000_00aa006d2ea4> >' to 'struct IDispat
ch ** '
我编的程序有错误吗,该如何改,我的那个组件是抄的,肯定是对的