ATL in the process of server registration mechanism in the process

xiaoxiao2021-03-06  41

1. In ATL3.0, the server is registered by an object mapping table. Begin_Object_map (ObjectMap)

Object_entry (CLSID_MYCIRCLECOLLECREATOR, CMYCIRCLECOLLECTIONCREATOR)

END_OBJECT_MAP ()

When an ATL registration server, eventually call to the AtlModuleRegisterServer function to register. For all objects supported by components, it creates a registry key for registration, and the registration process ends.

However, in the ATL7, the above three macros have been outdated, and the macro Object_Entry_Auto is replaced. Let's analyze the implementation of the macro Object_Entry_AUTO.

Second, the definition of macro object_entry_auto.

1. Let's first look at _ATL_OBJMAP_ENTRY definition:

Struct _tl_objmap_entry30

{

Const CLSID * PCLSID;

HRESULT (BOOL BREGOSTER)

_TL_CREATORFUNC * PFNGETCLASSOBJECT;

_TL_CREATORFUNC * PFNCREATEINSTANCE;

IUNKNOWN * PCF;

DWORD DWREGOSTER;

_TL_DESCRIPTIONFUNC * PFNGETOBJECTDESCRIPTION;

_TL_catmapfunc * pfNgetcategoryMap;

}

TYPEDEF _ATL_OBJMAP_ENTRY30 _ATL_OBJMAP_ENTRY

2. The definition of macro Object_entry_auto is as follows:

#define Object_ENTRY_AUTO (CLSID, CLAS)

__declspec (selectany) ATL :: _ ATL_OBJMAP_ENTRY __OBJMAP _ ## Class = /

{/

& clsid, /

Class :: UpdateRegistry, /

Class :: _ ClassFactoryCreatorClass :: CreateInstance, /

Class :: _ CreatorClass :: CreateInstance, /

NULL, /

0, /

Class :: getObjectDescription, /

Class :: getcategorymap,

Class :: Objectmain}; /

/

Extern "C" __DECLSPEC (Allocate ("ATL $ __ M")) /

__DECLSPEC (Selectany) ATL :: _ ATL_OBJMAP_ENTRY * const __pobjmap _ ## Class /

= & __ objmap _ ## class; /

Object_entry_pragma (Class)

3. Let's take a helpful macro object_entry_pragma, which is defined as follows:

#define object_entry_pragma (Class) /

__pragma (Comment (Linker, "/ include: ___ pobjmap_" #class));

Third, the function of macro Object_entry_Auto

1. Structural _tl_objmap_entry does not have to say more, and ATL3 is exactly the same.

2. Macro Object_ENTRY_AUTO features:

1) Use the information of CLSID, Class, generate _tl_objmap_entry, and the variable name is __objmap_ plus the actual value of the Class.

2) Declaring 1) A pointer to the generated example and assigns 1) The address of the generated instance. But the pointer is placed in the ATL $ _M segment.

3. The function of macro Object_entry_pragma is to tell the connector to add symbols ___objmap_ plus the actual value of Class to the symbol table. Note: Under the x86 platform, the symbol name is before the name is declared. So in the object_entry_pragma macro, there are three underscores before POBJMAP.

Fourth, in this section of the code to use Object_ENTRY_AUTO

Create an ATL7.0 project:

1. If you use non-property programming, it is automatically generated in the COM class's header file, don't delete the macro, otherwise you will not be able to create instances of this class. And such errors are very difficult to find.

2. If you are using property programming, then there is a CoClass property in front of the COM class, the compiler will insert some of the code to complete the following features from the code:

l Add the base class of the COM class

l Generate registration code

l Generate interface mapping table

l Generate object maps, namely Hong Object_ENTRY_AUTO

So in the code, you can't see Object_Entry_Auto.

5. Object_entry_auto and other parts of the system, the establishment and use of object mapping tables here.

If you use non-property programming, then the user can generate any legal COM class name; if we use the property programming, we don't know the name of the _tl_objmap_entry pointer variable, these for the ATL library, it is impossible to know the user-defined COM The name of the class. So how do it travers an object mapping table to update the registry?

The answer is the establishment of the object mapping table, let's first look at the beginning of the mapping table, end. Their definition is as follows:

__declspec (selectany) __DECLSPEC (Allocate ("ATL $ __ a")) _TL_OBJMAP_ENTRY * __POBJMAPENTRYFIRST = NULL;

__Declspec (selectany) __DECLSPEC (Allocate ("ATL $ __ Z")) _TL_OBJMAP_ENTRY * __POBJMAPENTRYLAST = NULL;

analyse as below:

l Neteming is that __ pobjmapenTryfirst, __ PobjMapENTRYLAST is placed in segment ATL $ _A and ATL $ _Z.

l Netemes again is that the variables placed through the macro Object_Entry_AUTO are in ATL $ _M.

l When the connector layout code, it is arranged according to the rules of the letter according to the name according to the name. This appears before the variables in Section ATL $ _A before the variables of Segment ATL $ _Z.

l Finally, use #pragma comment (Linker, "/merge :atl=.rdata), merge all the data in three segments into segment. RDATA read-only data segment.

l The last formation of the last may be as follows:

__POBJMAPENTRYFIRST ...

UserDefinedPtr1 UserDefinedPtr2 ...

__POBJMAPENTRYLAST

In this way, an object mapping table is formed. In the ATL library, you can locate the object mapping table according to __pobjmapentrylast, __ pobjmapentrylast, and all objects are registered.

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

New Post(0)