Recordset pointer

I have written a component, a method of which returns a _RecordsetPtr(a smart pointer) by converting it into a LPDISPATCH pointer.

For eg: Suppose the return value of the method is LPDISPATCH *disp and one of the variables declared in the method is _RecordsetPtr rs,then in the method I say rs->QueryInterface(IID_IDispatch,(void **)disp);

But when I call this component's method to retrieve the recordset from the LPDISPATCH pointer , I say

_RecordsetPtr = disp;

This does not give an error at compile time as  well as run time.But as well as it does not even display the  Recordset information when I call any of its methods,say  GetCount() which just retrieves the number of records in the Recordset.

Why is it so?

I can even use ADO connection ptr.
But my requirement is to use the above component and use smart pointers.

How do I convert a LPDISPATCH pointer to a _RecordsetPtr??

Who is Participating?
wildyConnect With a Mentor Commented:
I've done it with VARIANT but I think it's the same...

STDMETHODIMP CDriver::get_RecordsetX(VARIANT *pVal)
      if (pVal == NULL)
            return E_POINTER;

      if (m_pRec)

      _variant_t x(m_pRec.GetInterfacePtr(), ((m_pRec.GetInterfacePtr() == NULL) ? false : true));
      *pVal = x;

      return S_OK;

STDMETHODIMP CDriver::put_RecordsetX(VARIANT newVal)
      _variant_t x = newVal;

      if (m_pRec != NULL)
      if ((x.vt == VT_DISPATCH) || (x.vt == VT_UNKNOWN))
            m_pRec = x;
            if (m_pRec == NULL)
                  return S_FALSE;
      else if (x.vt == VT_EMPTY)
            m_pRec = x;
            return S_FALSE;

      return S_OK;

There are the get and put. I think that u are doing right but missing addref...
All Courses

From novice to tech pro — start learning today.