Upload
suga1990
View
247
Download
1
Embed Size (px)
Citation preview
7/30/2019 DCOM Interface
1/17
DCOM Interfaces
IUnknown
IDispatchIClassFactory
7/30/2019 DCOM Interface
2/17
IUnknown
Enables clients to get pointers to other interfaces
Manage the existence of the object through the
AddRefand Release methods.
All other COM interfaces are inherited, directly
or indirectly, from IUnknown.
Therefore, the three methods in IUnknown are
the first entries in the VTable for every interface.
implement IUnknown as part of every interface.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms691379(v=vs.85).aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms682317(v=vs.85).aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms682317(v=vs.85).aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms691379(v=vs.85).aspx7/30/2019 DCOM Interface
3/17
7/30/2019 DCOM Interface
4/17
7/30/2019 DCOM Interface
5/17
HRESULT QueryInterface(
[in] REFIID riid,
[out] void **ppvObject
);
Retrieves pointers to the supported interfaces on an object. This method calls IUnknown::AddRefon the pointer it
returns.
Return value
returns S_OK ->interface is supported
E_NOINTERFACE otherwise.
IfppvObjecti= NULL,returns E_POINTER.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms691379(v=vs.85).aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms691379(v=vs.85).aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms691379(v=vs.85).aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms691379(v=vs.85).aspx7/30/2019 DCOM Interface
6/17
Set of interfaces accessible on an object throughQueryInterface must be static, not dynamic.
if a call to QueryInterface for a pointer to a
specified interface succeeds the first time, it mustsucceed again, and if it fails the first time, it mustfail on all subsequent queries.
Reflexive
Symmetric
Transitive next
7/30/2019 DCOM Interface
7/17
must be reflexive if a client holds a pointer
to an interface on an object, and queries for
that interface, the call must succeed.
back
7/30/2019 DCOM Interface
8/17
must be symmetric if a client holding a
pointer to one interface queries successfully
for another, a query through the obtained
pointer for the first interface must succeed.
back
7/30/2019 DCOM Interface
9/17
must be transitive if a client holding a
pointer to one interface queries successfully
for a second, and through that pointer queries
successfully for a third interface, a query for
the first interface through the pointer for the
third interface must succeed.
back
7/30/2019 DCOM Interface
10/17
Binding is the term given to the process of matchingthe location of a function given a pointer to an object.
COM supports three types of binding:
Late. This is where type discovery is left until runtime.
Method calls made by the client but not implementedby the object will fail at execution time.
ID. Method IDs are stored at compile time, butexecution of the method is still performed through a
higher-level function. Custom vTable (early). Binding is performed at compile
time. The client can then make method calls directlyinto the object.
7/30/2019 DCOM Interface
11/17
IDispatch
The IDispatch interface supports late- and ID-binding languages. Late binding requires a call to the object to retrieve the list of method IDs;
The client must then construct the call to the Invoke method and call it.
The Invoke method must then unpack the method parameters and call thefunction.
All these steps add significant overhead to the time it takes to execute a method.
7/30/2019 DCOM Interface
12/17
ID binding offers a slight improvement over
late binding in that the method IDs are cached
at compile time, which means the initial call to
retrieve the IDs is not required.
However, there is still significant call overhead
because the IDispatch::Invoke method is still
called to execute the required method on theobject.
7/30/2019 DCOM Interface
13/17
Early binding, often referred to as custom vTablebinding, does not use the IDispatch interface.
Instead, a type library provides the required
information at compile time to allow the client toknow the layout of the server object.
At runtime, the client makes method calls directlyinto the object.
This is the fastest method of calling objectmethods and also has the benefit of compile-timetype checking.
7/30/2019 DCOM Interface
14/17
dual
Objects that support both IDispatch and custom vTable are referred to as dual
interface objects
7/30/2019 DCOM Interface
15/17
IClassFactory
When to implement
For every class that you register in the systemregistry and to which you assign a CLSID, so
objects of that class can be created. IClassFactory::CreateInstance : creates an
instance of component using CLSID
IClassFactory::LockServer : increment the refcount ,server stays in memory and doesnotshutdown before client finishes its work.
7/30/2019 DCOM Interface
16/17
IClassInterface
7/30/2019 DCOM Interface
17/17
Before a client creates an instance of a COM object,
1. It creates an instance of the object's class factory,(using CoGetClassObject()).
2. CoGetClassObject() calls the DllGetClassObject() in
the DLL.3. It creates the classFactory instance using CLSID and
IID and returns interface pointer to client
4. Using ClassFactory Instance the client then calls the
class factory's ClassFactory::CreateInstance method.5. ClassFactory::CreateInstance() creates a new instance
of the component and return the interface pointer tothe client