COM is a binary standard indeed, but once that coincides with the way the MS C++ compiler lays out a C++ class that only has pure virtual functions.Quote:
Originally Posted by Bubba
So, to define an interface, you simply do this:
Without treating it specially in any way, the C++ compiler will emit code that is binary compatible with COM.Code:
virtual UINT __stdcall AddRef() = 0;
virtual HRESULT __stdcall QueryInterface(void **ppv, REFIID iid) = 0;
virtual UINT __stdcall Release() = 0;
A COM object is just a class that inherits any number of interfaces and implements all the functions inside.
So yes, COM is just a binary standard, but it says about this:
An interface pointer points to a memory location where the first thing is a vtable pointer. This vtable pointer points to a memory location that contains function pointers. To call a function through COM, you first push the interface pointer to the stack, followed by all the parameters, from left to right. Then you dereference the interface pointer. You add the function-specific offset to the resulting pointer and call to the resulting address. After the call returns, you don't need to clean up the stack.
This is the exact way the MS compiler implements virtual function calls that use the __stdcall convention. The difference to the standard C convention is in the way parameters are passed, but not the call mechanism.
The bottom line is that the COM call overhead is equal to a virtual function call.