Click to See Complete Forum and Search --> : Passing ADO interfaces to ATL COM client


Tobbe
July 20th, 2000, 01:54 AM
I wan't to pass a connection object from my
ActiveX control to my ATL COM client. I have tried
to pass the dispatch interface but it didn't really work.

I'm thankful for any source code on this! (VC6)

Johnny101
July 22nd, 2000, 03:27 PM
I dont know about VC, but in VB I can specify that an incoming parameter is of type ADODB.Connection and then i can use it throughout my COM object.

'vb example
public Sub ExecuteCommand(cn as ADODB.Connection, sStatement as string)
'now the connection that is passed in to this procedure, we can use it.
If cn.State adStateOpen then
'the connection is closed - open it
cn.Open
End if

'now execute the command passed in...
cn.execute sql
End Sub




this does require that the ADO object library is referenced in the COM object. I think in C, it called "#import"-ing, maybe? You could set up a public property of the COM object and pass the connection into the object. That way the connection passed in will be available to the entire object:

'vb code
private m_CN as ADODB.Connection

public property let Connection(cn as ADODB.Connection)
set m_CN = cn
End property




now the whole COM object can use the m_CN connection object - so you wouldn't have to pass it in every time you wanted to use it.

hope this helps a little, at least.

good luck,

John


John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org