Problem in passing recordset from server to client
-
Hello, I have some sort of problem in COM while passing the ADO recordset object through variant to the client. In the server I can able to traverse through the recordset:-O . Once I got the variant at the client end, the variant contains the NULL (VT_EMPTY):confused: . What is the problem? For your clarity I'm putting some excerption from my coding. At Server_End HRESULT CServer::Function1(VARIANT *pvarRSObj, VARIANT *pvarRetVal) { _RecordsetPtr pRSObj = NULL; try { pRSObj->CreateInstance(__uuidof(Recordset)); pRSObj->Open(varQueryString, (IDispatch*)m_conObj, adOpenKeyset, adLockBatchOptimistic, adCmdText); pvarRSObj->vt = VT_DISPATCH; pvarRSObj->pdispVal = (IDispatch*)pRSObj; } catch(_com_error &e) { ERRBOX(e.ErrorMessage()); return e.Error(); } catch(...) { ERRBOX("Unknown Exception"); return E_FAIL; } return S_OK; } At Client_End InvokeServer() { IServer *pServer; //instantiation of server pServer->Function1(&varRSObj, &varResponse); CHECKVARIANTTYPE(&varRSObj); //It'll check the variant type // this is showing me that variant contains VT_EMPTY. if(varRSObj.vt == VT_DISPATCH) { //necessary action } } Timely reply appreciated. Regards, Ramesh
-
Hello, I have some sort of problem in COM while passing the ADO recordset object through variant to the client. In the server I can able to traverse through the recordset:-O . Once I got the variant at the client end, the variant contains the NULL (VT_EMPTY):confused: . What is the problem? For your clarity I'm putting some excerption from my coding. At Server_End HRESULT CServer::Function1(VARIANT *pvarRSObj, VARIANT *pvarRetVal) { _RecordsetPtr pRSObj = NULL; try { pRSObj->CreateInstance(__uuidof(Recordset)); pRSObj->Open(varQueryString, (IDispatch*)m_conObj, adOpenKeyset, adLockBatchOptimistic, adCmdText); pvarRSObj->vt = VT_DISPATCH; pvarRSObj->pdispVal = (IDispatch*)pRSObj; } catch(_com_error &e) { ERRBOX(e.ErrorMessage()); return e.Error(); } catch(...) { ERRBOX("Unknown Exception"); return E_FAIL; } return S_OK; } At Client_End InvokeServer() { IServer *pServer; //instantiation of server pServer->Function1(&varRSObj, &varResponse); CHECKVARIANTTYPE(&varRSObj); //It'll check the variant type // this is showing me that variant contains VT_EMPTY. if(varRSObj.vt == VT_DISPATCH) { //necessary action } } Timely reply appreciated. Regards, Ramesh
Hi, You can return a Recordset as an IDispatch pointer like this: STDMETHODIMP CMyClass::GetAllRecords(BSTR bstrSearchKey, IDispatch **output) { .... .... *output = (IDispatch*) pRecordset.Detach(); //Return recordset as IDispatch } Regards, ShadiK Shadi Al-Kahwaji