C ++ COM interface method access

AND

  • CLSID
  • IID

By specifying the above and using:

  • CoCreateInstance ()

Return a single uninitialized object of the class specified above CLSID.

How can I access an interface method from C ++? Without:

  • ATL
  • MFC
  • Just C ++

Subsequently I use CreateInstance ()

I'm having trouble using CreateInstance () - with the last parameter - ppv

Using oleview I can see methods of the above IIDabove IID like:

interface IS8Simulation : IDispatch {
    HRESULT Open([in] BSTR FileName);
};

      

How can I access the above? Examples / guide - please

Hello

+1


source to share


4 answers


By doing CoCreateInstance, you get a pointer to the interface. With the QueryInterface (...) method, you can easily get a pointer to the interface of another interface. eg.,

<code>
IUnknown * pUnk = NULL;
HRESULT hr = :: CoCreateInstance (clsid, NULL, CLSCTX_ALL, __ uuidof (IUnknown), (void **) and pUnk);

IS8Simulation * pSim = NULL; hr = pUnk-> QueryInterface (__ uuidof (IS8Simulation), (void **) & pSim);



Code>

After that, you will get a pointer to IS8Simulation in pSim and through it you can call the methods of this interface. Remember, you need to provide a valid clsid in the call to CoCreateInstance.

+5


source


It's a little vague what the actual problem is. Some code would be helpful. But to guess, you need QueryInterface?



0


source


 IS8Simulation* pSim = NULL;
 hr = pUnk->QueryInterface(__uuidof(IS8Simulation), (void)&pSim);

      

I will try to do it above, but IS8Simulation was announced - please excuse my lack of COM understanding

Also, how to call a method using plain C ++ :

HRESULT Open([in] BSTR FileName)

      

0


source


You probably want to #import "something.dll". This will give you C ++ declarations for types like IS8Simulation, similar to how #include "something.h" does.

0


source







All Articles