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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.