tags:

views:

463

answers:

4

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

A: 

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?

Brian
+5  A: 
Aamir
In the example, both the uuidof(..) calls should be preceeded by double underscores. I added that but somehow those are lost in formatting ( I should have escaped those probably)
Aamir
Aamir +1 for a good post, but rather than commenting on your own posts you are better to edit them. Keeps it clear for those just scannng through posts without looking at comments.
Shane MacLaughlin
Thanks Aamir, but - where is - IS8Simulation declared? How can I call methods from that interface, that contain parameters such as BSTR (illustrated above)
Aaron
well... using Oleview you can see the typelib information of the interface. This will tell you that from which binary the interface is coming from. It is normally something like win32 = 'something.dll'. This is the dll/tlb etc. which normally contains the declaration of this interface.
Aamir
I got the following compiler errors:`IS8Simulation' undeclared (first use this function)`pSim' undeclared (first use this function)`__uuidof' undeclared (first use this function)
Aaron
Don't forget to Release http://msdn.microsoft.com/en-us/library/ms682317(VS.85).aspx the interface pointer! Otherwise you will have memory leaks.
uvts_cvs
A: 
 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)
Aaron
once you have pointer to your interface i.e., pSim in above example, you can call its methods simply like..BSTR bstrFileName = ::SysAllocString(fileName);hr = pSim->Open(bstrFileName);Remember to free the BSTR after using by calling ::SysFreeString()And yes, this is plain C++
Aamir
Aamir, thanks again!!! :) I'll attempt the above, and will post my finding - you've been a big help wow!
Aaron
A: 

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

MSalters
I'm in the process of trying to compile IDL FILE using MIDL Compiler. I found type declarations like "single" (which is VB) - is this normal?
Aaron