If the reader is familiar with the implementation of C language class Class, it is not difficult to find that the VTABLE in the COM interface structure is exactly the same as the Class's vTable (class virtual function table), so describing the COM interface is the most convenient means. We can redefine IDictionary by C classes:
class IDictionary {virtual BOOL Initialize () = 0; virtual BOOL LoadLibrary (String) = 0; virtual BOOL InsertWord (String, String) = 0; virtual void DeleteWord (String) = 0; virtual BOOL LookupWord (String, String *) = 0; Virtual Bool Restorelibrary (String) = 0; Virtual Void Freelibrary () = 0;};
Because the CLASS definition hides the virtual function table vtable, and each member function hides the first parameter this, the THIS pointer points to an instance of the class. The memory structure of class iDictionary is exactly the same as the COM interface specification. Class IDictionary's instructions are obviously simpler than Struct iDictionary.
The instructions of Class iDictionary use a pure virtual function because the interface is only a description, not to provide a specific implementation process. If the COM object is to implement interface IDictionary, the COM object must be linked to class idictionary in some way, then exposing the IDictionary's pointer to the client, so the customer can call the object's dictionary function.
Let's see the case where the client calls, after the client gets the interface pointer Pidictionary of a dictionary object, she can call the member function of the interface. E.g:
Pidictionary-> loadingLibrary ("eNG_ch.dict");
If you use the C language Struct iDictionary, the interface member function should be like this:
Pidictionary-> PvTBL-> LoadLibrary (Pidictionary, "ENG_CH, DICT");
The characteristics of C language CALSS can be known that the above two calls are completely equivalent.
Selected from "COM principle and application" Pan Ai people.