Home   Index   About
Ultimate Pack


Custom Search
CoGetClassObject

Provides the caller with a pointer to an interface on a class object associated with a specified CLSID. The CoGetClassObject function transparently locates, and if necessary, dynamically loads the executable code required to do this.

Call CoGetClassObject when you want to create multiple objects through a class object for which there is a CLSID in the system registry. You would then call IClassFactory::CreateInstance to create an uninitialized object. It is not always necessary to go through this process. To create a single object, call instead the CoCreateInstance function, which encapsulates connecting to the class object, creating the instance, and releasing the class object. OLE also provides many other ways to create an object in the form of numerous helper functions and interface member functions whose function is to create objects of a single type and provide a pointer to an interface on that object.

STDAPI CoGetClassObject(

REFCLSID rclsid,
//CLSID associated with the class object
DWORD dwClsContext,
//Context for running executable code
LPVOID pvReserved,
//Must be NULL
REFIID riid,
//Interface identifier
LPVOID * ppv
//On return, pointer to location of interface pointer
);

Parameters

rclsid

Specifies the CLSID that will associate the correct data and code.

dwClsContext

Specifies the context in which the executable code is to be run. For information on the context values and their use, see the CLSCTX enumeration.

pvReserved

Reserved for future use. Must be NULL.

riid

Specifies the interface to be used to communicate with the class object. This interface is almost always IClassFactory (represented by the riid IID_IClassFactory).

ppv

Points to where the resulting interface pointer is to be stored.

Return Values

S_OK

Location and connection to the specified class object was successful.

REGDB_E_CLASSNOTREG

CLSID is not properly registered.

E_NOINTERFACE

The object pointed to by ppv does not support the interface identified by riid.

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 shutdown).

E_OUTOFMEMORY

Out of memory.

E_INVALIDARG

One or more arguments are invalid.

E_UNEXPECTED

An unexpected error occurred.

E_NOINTERFACE

The QueryInterface on the class object returned E_NOINTERFACE.

Comments

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 on a class object is IClassFactory, through which you can create object instances of a given definition (class).

A call to CoGetClassObject creates, initializes, and gives the caller access (through 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. Details of how code and data are located and associated are transparent to the caller, as is the dynamic loading of associated code not already loaded. There are two places to find a CLSID for a given object definition:

  • 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 or OleCreateXxx helper functions. These functions encapsulate the entire object instantiation and initialization process, and call, among other functions, CoGetClassObject.

The riid parameter specifies the interface the client will use to communicate with the class object. In most cases, this interface is IClassFactory. This provides access to the IClassFactory::CreateInstance member function, through which the caller can then create an uninitialized object of the kind specified in its implementation. All object definitions registered in the system with a CLSID must implement 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, used to transform the display name of an object into a moniker.

The dwClsContext parameter specifies the execution context, allowing one CLSID to be associated with different pieces of code in different execution contexts. The CLSCTX enumeration , defined in COMPOBJ.H, specifies the available context flags. CoGetClassObject consults (as appropriate for the context indicated) both the registration database and the class objects that are currently registered by calling the CoRegisterClassObject function.

See Also

CoRegisterClassObject, CoRevokeClassObject, OleLoad, CLSCTX


Last news from Greatis Software

Nostalgia .Net     Nostalgia .Net     .Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes.  More »

Recommended software for developers

Ultimate Pack for Delphi and C++ Builder     Ultimate Pack     Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price.  More »

Form Designer .Net     Form Designer .Net     Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro!  More »

Print Suite .Net     Print Suite .Net     Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available  More »

Gradient Controls .Net     Gradient Controls .Net     Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available  More »

iGrid     Greatis iGrid     iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors.  More »


All the contacts and projects

Dmitry Vasiliev (just.dmitry)

Related Links

Software for Visual Studio .NET developers
Software for Delphi and C++ Builder developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET

More Online Helps

Win32 Programmer's Reference
Win32 Multimedia Programmer's Reference
OLE Programmer's Reference
Microsoft Windows Pen API Programmer's Reference
Microsoft Windows Sockets 2 Reference
Microsoft Windows Telephony API (TAPI) Programmer's Reference
Unix Manual Pages

Free Tech Secrets ;) Copyright © 2008-2012 Free Tech Secrets ;) greatis just4fun network just4fun