CoGetClassObject
Provides a
pointer to an interface on a class object associated with a specified CLSID. CoGetClassObject
locates, and if necessary, dynamically loads the executable code required to do
this.
Call CoGetClassObject
directly when you want to create multiple objects through a class object for
which there is a CLSID in the system registry. You can also retrieve a class
object from a specific remote machine. Most class objects implement the IClassFactory
interface. You would then call IClassFactory::CreateInstance
STDAPI CoGetClassObject(
REFCLSID rclsid, |
//CLSID associated with the class object |
DWORD dwClsContext, |
//Context for running executable code |
COSERVERINFO * pServerInfo, |
//Pointer to machine on which the object is to be
instantiated |
REFIID riid, |
//Reference to the identifier of the interface |
LPVOID * ppv |
//Indirect pointer to the interface |
); |
|
Parameters
rclsid
[in] CLSID
associated with the data and code that you will use to create the objects.
dwClsContext
[in] Context
in which the executable code is to be run. To enable a remote activation,
CLSCTX_REMOTE_SERVER must be included. For more information on the context values
and their use, see the CLSCTX
pServerInfo
[in] Pointer
to machine on which to instantiate the class object. May be NULL, in which case
the class object is instantiated on the current machine or at the machine
specified under the class s RemoteServerName._W2BG key in the registry, according to the
interpretation of the dwClsCtx parameter (see the CLSCTX documentation
for details).
riid
[in]
Reference to the identifier of the interface, which will be supplied in ppv
on successful return. This interface will be used to communicate with the class
object. Typically this value is IID_IClassFactory, although other values
- such as IID_IClassFactory2
which supports a form of licensing - are allowed. All OLE-defined interface IIDs are defined in the OLE
header files as IID_interfacename, where interfacename is
the name of the interface.
ppv
[out] On
successful return, indirect pointer to the requested interface.
Return Values
S_OK
Location and
connection to the specified class object was successful.
REGDB_E_CLASSNOTREG
CLSID is not
properly registered. Can also indicate that the value you specified in dwClsContext
is not in the registry.
E_NOINTERFACE
Either the
object pointed to by ppv does not support the interface identified by riid,
or the QueryInterface operation on the class object returned
E_NOINTERFACE.
REGDB_E_READREGDB
Error reading
the registration database.
CO_E_DLLNOTFOUND
In-process
DLL or handler DLL not found (depends on context).
CO_E_APPNOTFOUND
EXE not found
(CLSCTX_LOCAL_SERVER only).
E_ACCESSDENIED
General
access failure (returned from LoadLib/CreateProcess).
CO_E_ERRORINDLL
EXE has error
in image.
CO_E_APPDIDNTREG
EXE was
launched, but it didn t register class object (may or may not have shut down).
Remarks
A class object
in OLE is an intermediate object that supports an interface that permits
operations common to a group of objects. The objects in this group are instances
derived from the same object definition represented by a single CLSID. Usually,
the interface implemented on a class object is IClassFactory
A call to CoGetClassObject
creates, initializes, and gives the caller access (through a pointer to an
interface specified with the riid parameter) to the class object. The
class object is the one associated with the CLSID that you specify in the rclsid
parameter. The details of how the system locates the associated code and data
within a given machine are transparent to the caller, as is the dynamic loading
of any code that is not already loaded.
If the class
context is CLSCTX_REMOTE_SERVER, indicating remote activation is required, the COSERVERINFO
There are two
places to find a CLSID for a given class:
The registry holds an
association between CLSIDs and file suffixes, and between CLSIDs and file
signatures for determining the class of an object.
When an object is saved to
persistent storage, its CLSID is stored with its data.
To create and
initialize embedded or linked OLE document objects, it is not necessary to call
CoGetClassObject directly. Instead, call one of the OleCreate
The riid
parameter specifies the interface the client will use to communicate with the
class object. In most cases, this interface is IClassFactory
In rare
cases, however, you may want to specify some other interface that defines
operations common to a set of objects. For example, in the way OLE implements
monikers, the interface on the class object is IParseDisplayName
The dwClsContext
parameter specifies the execution context, allowing one CLSID to be associated
with different pieces of code in different execution contexts. The CLSCTX
To release a
class object, use the class object s Release method. The function CoRevokeClassObject
is to be used only to remove a class object s CLSID from the system registry.
See Also