Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. ATL and ADO Problem

ATL and ADO Problem

Scheduled Pinned Locked Moved ATL / WTL / STL
questionc++help
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Popeye Doyle Murray
    wrote on last edited by
    #1

    I am writing an ATL component to do some data access using ATO. I want to pass a _RecordsetPtr pointer or a _ConnectionPtr to a ATL function. I use code like this: STDMETHODIMP CMyAtlObject::ReadData(LPDISPATCH pAdoRecordset, BOOL *pbSuccess) { _RecordsetPtr pRecordsetPtr; if (FAILED(pAdoRecordset->QueryInterface(IID_IDispatch, (void**) &pRecordsetPtr))) { return S_FALSE; } // do somethign here with the recordset return S_OK; } But this doesn't work. The recordset pointer gets closed during the function call. If I pass an _ConnectionPtr as LPDISPATCH, the pointer becomes invalid. So how can I pass valid ADO _RecordsetPtr's and _ConnectionPtr's to an ATL Object?

    S 1 Reply Last reply
    0
    • P Popeye Doyle Murray

      I am writing an ATL component to do some data access using ATO. I want to pass a _RecordsetPtr pointer or a _ConnectionPtr to a ATL function. I use code like this: STDMETHODIMP CMyAtlObject::ReadData(LPDISPATCH pAdoRecordset, BOOL *pbSuccess) { _RecordsetPtr pRecordsetPtr; if (FAILED(pAdoRecordset->QueryInterface(IID_IDispatch, (void**) &pRecordsetPtr))) { return S_FALSE; } // do somethign here with the recordset return S_OK; } But this doesn't work. The recordset pointer gets closed during the function call. If I pass an _ConnectionPtr as LPDISPATCH, the pointer becomes invalid. So how can I pass valid ADO _RecordsetPtr's and _ConnectionPtr's to an ATL Object?

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      Although I use OLE DB directly rather than ADO, unless the function explicitly requires a smart pointer, I'd be inclined to use a regular interface pointer instead, to save an AddRef and Release on construction/destruction of the temporary object. Steve S [This signature space available for rent]

      P 1 Reply Last reply
      0
      • S Steve S

        Although I use OLE DB directly rather than ADO, unless the function explicitly requires a smart pointer, I'd be inclined to use a regular interface pointer instead, to save an AddRef and Release on construction/destruction of the temporary object. Steve S [This signature space available for rent]

        P Offline
        P Offline
        Popeye Doyle Murray
        wrote on last edited by
        #3

        So how do I do that?

        S 1 Reply Last reply
        0
        • P Popeye Doyle Murray

          So how do I do that?

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          Where does your LPDISPATCH come from in the first place? That's an IDispatch, so using QueryInterface(IID_IDISPATCH, ...) is a no-brainer, it should just AddRef(). Are you using #import to pull in the ADO stuff? To get the recordset ptr, you should use __uuidof(_Recordset) in place of IID_IDISPATCH. This will either fail or fill in your _RecordsetPtr properly. Probably need more context to help more. Steve S [This signature space available for rent]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups