Objects in COM and objects in C ++

zhaozj2021-02-11  187

Object of the COM objects in C : Building the Wealth of Nations Published: 2001/02/07

Thesis:

I have been studying COM technology. I always feel that some concepts in COM are more difficult. For example, this concept is very different from the concept of objects in C . This article is simple and analyzed for beginners.

text:

The objects in COM and the object of C have also been a period of time. I always feel that some concepts in COM are more difficult. For example, this concept is very different from the concept of objects in C , and now simply analyzed, at first Scholar reference. In general, the object in COM / DCOM is called Windows object, which is different from C objects. The main reason is in C , we can only use it in your own application (exe) or in DLL Presence and execute C objects. On the other hand, when using the Windows object, it may not be considered where it exists and execute, or in its own EXE, or in the DLL, it can be in this unit, or any one in the network. Table host. Therefore Windows has stronger features. Several key points that affect the programming implementation between the Windows objects and C objects have the following aspects: • Definition of the object class. · Instantiation of the object. · The reference of the object. · The destruction of the object. Object-class definitions C we use Class this keyword to define classes, which is generated a user-defined type. Member data and member functions can be private, protected, and public, and C classes can inherit another class and inherited by another class, it can get all characteristics of the base class (data and member functions), and have transcendence and expand base classes The ability to select items. The Windows object is defined by the form of the interface he supported. All Windows objects must support a interface called IUNKNOWN. An object only supports this interface to refer to a Windows object, and an object user has aware of other interfaces supported by IUNKNOWN's member functions. The instantiation of the object can be instantiated by a variety of ways, such as declaring a variable of the object type on the stack, declare a full variable, or using a New operator for this type. But whether it is actually used, C ultimately calls the constructor's constructor. Similarly, there are many ways to instantiate the Windows object. In some cases, a function can be invigured to instance objects, and in some cases, the object cannot be directly instance, but a pointer to which some other contents that have been created. Here is the most common technique, that is, a tool called Class Factory Object (factory object), very much like the New operator does that the C object is made, and a class plant object represents a specific The category is obtained by a specific OLE2 or COM / DCOM function and supports an interface called ICLASSFACTORY. The IclassFactory interface contains a member function called CreateInstance that delivers a monetar of the interface we want on the object. IclassFactory :: CreateInstance and New are logically equal. The reference C object of the object can be referenced by object variables, object references (one specific type in C ), or pointers pointed. Since the object is usually locally (in the user's EXE or DLL), there is anywhere in the process space. With any variable, in the case of users and objects are friends, the user has access to any public, proprietary or protected member of the object. But Windows objects are typically referenced by an interface pointer instead of the object itself. This means that by an existing interface pointer, the user can only access member functions in the interface.

转载请注明原文地址:https://www.9cbs.com/read-4997.html

New Post(0)