Trying to Get an Instance of a COM object

This forum is reserved for everything you want to talk about. It could be about programming, opinions, open source programs, development in general, or just cool stuff to share!
Post Reply
noel
Earned a small fee
Earned a small fee
Posts: 19
Joined: Wed Nov 22, 2006 8:52 pm

Trying to Get an Instance of a COM object

Post by noel »

Recently I asked similar question - how to create an Instance of a COM objcet - and it's like this:

Code: Select all

wxAutomationObject *ado = new wxAutomationObject;
wxAutomationObject cnn;
wxString cnnString = "Provider=MSDASQL.1;Mode=Read;Extended Properties='DRIVER=SQL Server;SERVER=(local);UID=User;PWD=****;APP=some_app;WSID=name'";

HRESULT     hrADO;

const CLSID CLSID_ADO = {0x00000514,0x0000,0x0010,{0x80,0x00,0x00,0xAA,0x00,0x6D,0x2E,0xA4}};

        CoInitialize(NULL);
        IDispatch* pDispatchADO;

        hrADO = CoCreateInstance(CLSID_ADO, NULL,CLSCTX_INPROC_SERVER, IID_IDispatch, (void**)&pDispatchADO);


        if ( SUCCEEDED ( hrADO ) )
        {
         wxMessageBox (_T("CoCreateInstance ADO OK!!"));
        }
        else
        {
         wxLogError(_T("Error code = %08X"), hrADO);
        }

        ado->SetDispatchPtr(pDispatchADO);
        ado->CallMethod("open", cnnString);
and it works perfect !

Now I have problem. How to get an existing instance of a COM object. The COM object is created by another aplicattion.
In VB it's like: cnn=GetAdoConnection() and thats all.
Is there any method similar to: CoCreateInstance - but not to Create, but to Get ???
WriteLn or not WriteLn ;)
Post Reply