Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use this returned IDispatch interface?

0 views
Skip to first unread message

bucher

unread,
Nov 26, 2009, 8:30:51 PM11/26/09
to
Hi,

In my project I want to export an ado connection interface and use it.

The code like this:
STDMETHODIMP CDBInterface::OpenDBConnect(IDispatch **pConnect)
{
_ConnectionPtr pConn;
if (OpenDBConnection(pConn))
{
*pConnect = (IDispatch*)pConn;
pConn->AddRef();
return S_OK;
}else{
return E_FAIL;
}
}

STDMETHODIMP CDBInterface::SQLQueryWitchConn(BSTR sql, IDispatch *pConnect,
IATLRecordset **pRecordSet)
{
CComObject<CATLRecordset>* pClsRecordset = NULL;
HRESULT hr = CComObject<CATLRecordset>::CreateInstance(&pClsRecordset);
if (SUCCEEDED(hr))
{
try{
_ConnectionPtr ptrConn(pConnect);
...
}catch(_com_error& COMErr){
Error((char*)(COMErr.Description()));
hr = E_FAIL;
}
}

return hr;
}

But av exception occurs when I try to create an _ConnectionPtr with returned
IDispatch interface. How can I fix this problem?
Thanks in advanced.


Scot Brennecke

unread,
Nov 28, 2009, 12:47:40 AM11/28/09
to
A _ConnectionPtr is a smart pointer, and I don't think it wraps anything
that is derived from IDispatch, nor does it have a conversion operator
for IDispatch *. What makes you believe this should be possible?

Brian Muth

unread,
Nov 30, 2009, 3:17:14 PM11/30/09
to
Scott is correct. A _Connection interface is not an IDispatch interface, so
your attempt to expose this interface in this manner is not possible.
Moreover, I don't believe the _Connection interface can be marshaled.

What is the bigger goal here? Generally speaking, database connections
should be opened late and closed early. They cannot be passed from one
application to another (if that is what you are contemplating).

"bucher" <buc...@xxx.com> wrote in message
news:u5Z49Ewb...@TK2MSFTNGP02.phx.gbl...

0 new messages