IGlobalInterfaceTable

Allows any apartment in a process to get access to an interface implemented on an object in any other apartment in the process. The three methods allow you to do the following:
프로세스 내의 어떤 아파트먼트에서든 어떤 다른 아파트먼트안에서 구현된 객체의 인터페이스를 접근할 수 있도록 한다.

Register an interface as a global (processwide) interface.
Get a pointer to that interface from any other apartment through a cookie.
Revoke the global registration of an interface.
The IGlobalInterfaceTable interface is an efficient way for a process to store an interface pointer in a memory location that can be accessed from multiple apartments within the process, such as processwide variables and agile (free-threaded marshaled) objects containing interface pointers to other objects.
프로세스 전역 인터페이스로 등록한다.
각 다른 아파트먼트는 쿠키값으로 구분하여 등록된 인터페이스의 포인터를 얻는다.


An agile object is unaware of the underlying COM infrastructure in which it runs—in other words, what apartment, context, and thread it is executing on. The object may be holding on to interfaces that are specific to an apartment or context. For this reason, calling these interfaces from wherever the agile component is executing may not always work properly. The global interface table avoids this problem by guaranteeing that a valid proxy (or direct pointer) to the object is used, based on where the agile object is executing.

The global interface table is not portable across process or machine boundaries, so it cannot be used in place of the normal parameter-passing mechanism.

Note   IGlobalInterfaceTable is available on Microsoft® Windows NT® 4.0, Service Pack 3 and later. It is also available on Microsoft Windows® 95 with DCOM version 1.1 and later.

When to Implement
You should not implement this interface. The standard implementation provides complete thread-safe functionality.

When to Use
Use this interface when an interface implemented on an object in one apartment must be stored in memory accessible for use by other apartments. To create the global interface table object and get a pointer to this interface, make the following call:

CoCreateInstance(CLSID_StdGlobalInterfaceTable,
                            NULL,
                            CLSCTX_INPROC_SERVER,
                            IID_IGlobalInterfaceTable,
                            (void **)&gpGIT)

Note   When creating the global interface table object using the above call, you must link to the library Uuid.lib. This will resolve the external symbols CLSID_StdGlobalInterfaceTable and IID_IGlobalInterfaceTable.

There is a single instance of the global interface table per process, so all calls to this function in a process return the same instance.

After calling the CoCreateInstance function, register the interface you want to make available processwide from the apartment in which it resides with a call to the RegisterInterfaceInGlobal method. This supplies a pointer to a "cookie" (through the pdwCookie parameter) that identifies the interface and its location. An apartment that wants a pointer to this interface then calls the GetInterfaceFromGlobal method with this cookie, and the implementation then supplies an interface pointer to the calling apartment. To revoke the interface's global registration, any apartment may call the RevokeInterfaceFromGlobal method.

A simple example of its use would be when you want to pass an interface pointer on an object in a single-threaded apartment (STA) to a worker thread in another apartment. Rather than having to marshal it into a stream and pass the stream to the worker thread as a thread parameter, this interface allows you simply to pass a cookie.

When you register the interface in the global interface table, you get a cookie that you can use instead of passing the actual pointer whenever you need to pass the pointer either to a nonmethod parameter that is going to another apartment (as a parameter to ThreadProc via CreateThread) or to in-process memory accessible outside your apartment.

Care is required because using globals places the extra burden on the programmer of managing problems such as race conditions and mutual exclusion, which are associated with accessing global state from multiple threads simultaneously.

Methods in Vtable Order
IUnknown Methods Description
QueryInterface Returns pointers to supported interfaces.
AddRef Increments the reference count.
Release Decrements the reference count.
IGlobalInterfaceTable Methods Description
RegisterInterfaceInGlobal Permits access to a given interface from any apartment in a process.
RevokeInterfaceFromGlobal Revokes the registration of a global (processwide) interface.
GetInterfaceFromGlobal Gives the calling apartment access to an interface registered as global.

Requirements
  Windows NT/2000/XP: Requires Windows NT 4.0 SP3 or later.
  Windows 95/98: Requires Windows 98 (or Windows 95 with DCOM 1.2).
  Header: Declared in objidl.h.

'KB > MFC/Win32' 카테고리의 다른 글

PE 헤더 정보  (0) 2006.06.16
Design and Implementation of Power-Aware Virtual Memory  (0) 2006.06.12
COM 스레드 모델 STA, MTA  (0) 2006.03.24
원격 프로세스 제어 (원격 스레드 생성)  (0) 2006.02.01
TCP 성능 향상  (0) 2006.01.31

+ Recent posts