[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-atl
Subject:    QueryInterface Blues (was ADO Objects)
From:       Chuck Horan <chuck () TORNET ! COM>
Date:       1997-10-31 14:16:46
[Download RAW message or body]


I don' t think that casting an interface pointer is such a good idea, that
is what
QueryInterface is for, to SAFELY return a new, supported interface pointer.

I guess the real question is WHAT is VB passing as a paramater?????

Full sample code follows

----Start VB
    Dim rs As Object
    Dim c As Object
    Dim t As New mylib.myObject
    Dim foo As String

    Set c = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset") '<==Redundant
    c.open "MYDSN", "sa", "password"
    Set rs = c.execute("select * from titles")

    Text1.Text = t.MyMethod(rs) '<==Call to ATL Server
---End VB


--Start ATL Code
#include <oledb.h>
#include <adoid.h>
#include <adoint.h>
STDMETHODIMP CObject:MyMethod(VARIANT rs,BSTR *retval)
{

        IRowset *Irs=NULL;
        IUnknown *pUnk=NULL;
        HRESULT hr;
        CComBSTR cbs;

        if (FAILED(hr = ((IDispatch
*)rs.ppdispVal)->QueryInterface(IID_IUnknown,(LPVOID *)&pUnk)))
                return S_OK;

        if (FAILED(hr = pUnk->QueryInterface(IID_IADORecordset,(LPVOID *)&Irs)))
                cbs.AppendBSTR(CComBSTR("It as not an ADO Recordset\n"));
        else
                cbs.AppendBSTR(CComBSTR("OK It is a an ADO Recordset\n"));

        if (FAILED(hr = pUnk->QueryInterface(IID_IADOCollection,(LPVOID *)&Irs)))
                cbs.AppendBSTR(CComBSTR("It is NOT a Collection\n"));
        else
                cbs.AppendBSTR(CComBSTR("OK It is a Collection\n"));

        if (FAILED(hr = pUnk->QueryInterface(IID_IADOCommand,(LPVOID *)&Irs)))
                cbs.AppendBSTR(CComBSTR("It is NOT a Command\n"));
        else
                cbs.AppendBSTR(CComBSTR("OK It is a Command\n"));

        if (FAILED(hr = pUnk->QueryInterface(IID_IADOConnection,(LPVOID *)&Irs)))
                cbs.AppendBSTR(CComBSTR("It is NOT a Command\n"));
        else
                cbs.AppendBSTR(CComBSTR("OK It is a Connection\n"));

        if (FAILED(hr = pUnk->QueryInterface(IID_IRowset,(LPVOID *)&Irs)))
                cbs.AppendBSTR(CComBSTR("It is NOT a rowset\n"));
        else
                cbs.AppendBSTR(CComBSTR("OK It is a recordset\n"));

        pUnk->Release();
        //retval always is "It as not an ADO Recordset\nIt is NOT a Collection\nIt
is NOT a Command\nIt is NOT a Command\nIt is NOT a rowset\n"
        //If is not any of these what the heck is it
        *retval = cbs.Detach();

        return S_OK;
}

--End ATL Code
TTFN

Chuck Horan
mailto:chuck@tornet.com
http://activehelp.tornet.com

-----Original Message-----
From:   Vince Holt [SMTP:vholt@ttransit.co.uk]
Sent:   Friday, October 31, 1997 2:57 AM
To:     chuck@tornet.com
Subject:        Re: Re Re Re ADO Objects


        I may be off track here, but I think you may need to cast the
dispatch/IUnknown ptr to an ADO ptr before doing the query interface.

______________________________ Reply Separator
_________________________________
Subject: Re Re Re ADO Objects
Author:  CHUCK@SMTP (Chuck Horan) {chuck@TORNET.COM} at MHS
Date:    10/30/97 11:54 PM


I think I need new glasses :) missed the second underscore, unfortuneately
when I
try to use it I get an undefined error.
I am including <adoint.h>, haven't figured this out yet,....



TTFN
mailto://chuck@tornet.com
http://activehelp.tornet.com

There is a IID__Recordset (note the 2 underscores).

Ryan

> -----Original Message-----
> From: Chuck Horan [SMTP:chuck@TORNET.COM]
> Sent: Thursday, October 30, 1997 7:11 PM
> To:   ATL@LISTSERV.MSN.COM
> Subject:      Re ADO Objects
>
> So far as I can tell there is no IID_Recordset interface.
>
> The reason I want IID_IRowset rather than IID_IADORecordset is that I
> want
> to be able to
> work with any OLE DB Data provider, not just ADO.
>
>
>
> TTFN
>
> Chuck Horan
> mailto:chuck@tornet.com
> http://activehelp.tornet.com
>
> -----Original Message-----
> From:   Ryan Reid [SMTP:ryanr@MOSSMICRO.COM]
> Sent:   Thursday, October 30, 1997 2:40 PM
> To:     ATL@LISTSERV.MSN.COM
> Subject:        Re: ADO Objects
>
> I think that you want to get IID__Recordset, not IID_IRowset.
>
> Ryan
>
> > -----Original Message-----
> > From: Chuck Horan [SMTP:chuck@TORNET.COM]
> > Sent: Thursday, October 30, 1997 1:29 PM
> > To:   ATL@LISTSERV.MSN.COM
> > Subject:      ADO Objects
> >
> > I am passing an ADO Recordset object into a DLL as a variant.
> > The variant shows as as IDispatch, so far so good.
> >
> > When I attempt to get a different interface pointer (ex IRowSet ) it
> > returns E_NOINTERFACE.
> > ----Sample code
> >
> >         VARIANT rs; //<- in param
> >         BSTR retval;// <- out param
> >         IRowSet *Irs;//Local var
> >
> >         if (FAILED(hr = ((IDispatch
> > *)rs.ppdispVal)->QueryInterface(IID_IUnknown,(LPVOID *)&pUnk)))
> >                 return S_OK;
> >
> >         if (FAILED(hr = pUnk->QueryInterface(IID_IRowset,(LPVOID
> > *)&Irs)))
> >         {
> >                 *retval=SysAllocString(L"It is NOT a rowset");
> >         }
> >         else
> >         {
> >                 *retval=SysAllocString(L"OK It is a rowset");
> >
> >         }
> >
> > ---End Sample
> > Am I going crazy I would expect it to return a IRowset Interface
> > pointer.'
> >
> > Any help would be appreciated
> >
> >
> > TTFN
> > mailto://chuck@tornet.com
> > http://activehelp.tornet.com
> >
> > ----------------------------------------------------------------
> > Users Guide
> http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
> > contains important info including how to unsubscribe.  Save time,
> > search
> > the archives at http://microsoft.ease.lsoft.com/archives/index.html
>
> ----------------------------------------------------------------
> Users Guide http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
> contains important info including how to unsubscribe.  Save time,
> search
> the archives at http://microsoft.ease.lsoft.com/archives/index.html
>
> TTFN
> mailto://chuck@tornet.com
> http://activehelp.tornet.com
>
> ----------------------------------------------------------------
> Users Guide http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
> contains important info including how to unsubscribe.  Save time,
> search
> the archives at http://microsoft.ease.lsoft.com/archives/index.html

----------------------------------------------------------------
Users Guide http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
contains important info including how to unsubscribe.  Save time, search
the archives at http://microsoft.ease.lsoft.com/archives/index.html

----------------------------------------------------------------
Users Guide http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
contains important info including how to unsubscribe.  Save time, search
the archives at http://microsoft.ease.lsoft.com/archives/index.html

----------------------------------------------------------------
Users Guide http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
contains important info including how to unsubscribe.  Save time, search
the archives at http://microsoft.ease.lsoft.com/archives/index.html

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic