Dr. Gui on Components, COM, and ATL Download this e-book from the VCKBase website, I read Dr. Gui discussion COM second part today. I tried him to translate him, as as a bit of learning COM knowledge. I I want to learn good com, this idea is half a year ago, until today, I haven't progressed, because there is no place to record the notes. I finally found 9CBS blog, I will have to learn / think about some things I have learned. Part II: COM foundation
In the first part, the doctor talks about why the language like C does not resolve the problem that allows you to prepare non-binary components. The point of discussion is that C is not intended to solve this problem; on the contrary, it makes single-execute program reply It is easier to .c put that target very well. But we hope to mix and match components from different sellers, do not need to re-establish part (or all) systems each time a component changes. We list why a lot is This scenario cannot be operated.
What? You must abandon C ? No - but you have to use a way to have a difference with your habits. That is next, I will discuss - how to use COM in C .
Is that means that if you are not a C programmer, should you stop reading? Not, because any COM-compatible language you use (Visual Basic, Visual J , Delphi, And Others) will do it Talking about the insider. So if you continue, you will get valuable knowledge about how the ActiveX controls and COM components work.
One What is Com Component Object Model (COM) is a way to communicate with each other. It's a binary and network standard That Allows Any Two Components To Communicate Regardless of What Machine They're Running On (As Long As the Machines) Are Connected, What Operating Systems The Machines Are Running (As Long AS It Supports COM), and what language the Components Are Written In. Com Further Provides Location Transparency.
Two objects (Objects) COM-based object-based (Objects) - but that is different from the object you use in C or Visual Basic [Translator Note: Pay attention to English and Chinese, I will show the original text] (by way of one sentence, one Objects and one component more points. DR. GUI called "Components" when talking to the application framework, is called "object" when talking to execution (IMPLEMENTATIONS).) First, COM objects will be good package. You can't Get the power to perform internal execution. You can't know the data structure that the object may be used. In fact, the object is such a good package and the COM object usually in the box. Triple interface: The communication is next to the interface. Close to a COM The only way for objects is through the interface. A number of objects containing IFOO is drawn below. One interface represents two things. First, it is a series of functions that you can call the object. In C , interface Abstract base class representative. For example, ifoo interface may be: Class ifoo {
Virtual void func1 (void) = 0;
Virtual void func2 (int ncount) = 0;
}
We will temporarily ignore the return value and inheritance. But please note that you can do more than one function in the interface, and all functions are pure virtual functions: they do not execute in class IFOO. I didn't define behavior - we only defined There are functions in the interface. (A true object has an actant, of course, - that is later.) Second - a very important point - an interface is a contract and client contract (Contract). In other words, one The interface not only defines what function is available, it also defines what is doing what objects when the function call is (Does). This language is not based on the specific execution of the object, so it can't play in the C code. 4 interface contract: like Diamond, always in COM, once you "compile" through the transfer component, July is eternal - it can't be changed in any form. You can't add, you can't delete, you can't modify it. Why? Because other Components depend on this contract. If you change the contract, you will subvert the program. As long as you follow the contract, you can improve your internal execution. If you have forgotten? If you need to make a change? How to change? • The answer is simple: you write a new contract. The standard OLE interface list has the following: iClassFactory and iClassFactory2, iViewObject, and iViewObject2, and so on. And IFOO2. Five COM objects support multiple interfaces --- They can perform multiple contract
The new interface is usually the form of the following: Class ifoo2: public ifoo {
// inherited func1, func2
Virtual Void Func2ex (double ncount) = 0;
}