Question

Both:

  • CLSID
  • IID

Having specified the above, and using:

  • CoCreateInstance()

To returning a single uninitialised object of the class specified by the CLSID above.

How can I then access an Interface's method from C++? Without:

  • ATL
  • MFC
  • Just plain C++

Afterwards, I use CreateInstance()

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

Using oleview, I can see methods of the specified IIDabove IID above, such as:

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

How can I then access the above? Examples/guidance - please

Regards

Was it helpful?

Solution

By doing a CoCreateInstance you get an interface pointer. Through QueryInterface(...) method you can get the interface pointer of some other interface easily. e.g.,


IUnknown* pUnk = NULL;
HRESULT hr = ::CoCreateInstance(clsid,NULL,CLSCTX_ALL,__uuidof(IUnknown),(void**)&pUnk);

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

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

OTHER TIPS

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

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

I'll attempt the above, but were is IS8Simulation declared - please excuss my lack of COM understanding

Furthermore, how to call the method, below using plain C++:

HRESULT Open([in] BSTR FileName)

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top