Can someone help me understand the concept of the COM "interfaces"?

I went to the msdn page where they explain the COM interfaces in a very complex way, but i have a hard time understanding the concept of these COM interfaces.

From what I understand, these interfaces are similar to data types, in the sense that you can use the name of the interface (for example: IFileOpenDialog) and declare a pointer or object.
 
IFileOpenDialog *pointer_to_interface;


Once i declare a pointer to an interface, then i can use that same pointer to call all the BUILT IN functions of the interface. But my question is, what exactly am i creating if i call an interface function (for example: CoCreateInstance())?

Can someone please explain to me in slightly simple words about the point of these interfaces? and why should i use them at all?
Last edited on
I'm pretty certain that COM interfaces are implemented as C++ abstract classes(I.e., every member function is pure virtual). When you call CoCreateInstance() or similar function you are essentially instantiating an object of that class, which will use Windows' default implementation of those virtual function.

I don't know a whole lot about the internal workings of COM, but it is simple enough to use COM API's when you realize that COM interfaces are classes that are instantiated using some COM function or member function of another COM interface.

As for why you should use them, well, most all new API's in Windows are using COM.

Oh, and don't forget that you have to free your COM objects manually by calling the interface method Release() on them!
Last edited on
closed account (z05DSL3A)
SomeAmazingGuy wrote:
I went to the msdn page where they explain the COM interfaces in a very complex way, but i have a hard time understanding the concept of these COM interfaces.
Which part of MSDN? If it wasn't the "Learn to Program for Windows in C++ (Module 2. Using COM in Your Windows Program)" section then take a look at that.
https://msdn.microsoft.com/library/windows/desktop/ff381399(v=vs.85).aspx
Thank you very much for those links, they really are helping a lot.

But if I may, I want to ask a few questions to make sure i COMPLETELY understand the concepts of these COM interfaces.

Does every interface have only one INTENDED functionality? for example, if we use the IFileOpenDialog interface, does that mean that we can only create an open file dialog box with the interface?
Last edited on
Topic archived. No new replies allowed.