All COM/DCOM component class follow factory design pattern. Constructor in factory design is private can new operator gives compilation error and object is not allocated directly using new operator by client. Factory design suggests a call to a creation function. Server allocates and returns the object and object memory management of allocation and deallocation is done in server side.
CreateInstance() is the factory provider function. A com component class should provide an IClassFactory interface for creating different objects from the component. Client indirectly calls this function with argument as the identity of the interface class. Com server creates and initializes an instance of the given co-class and returns the instance to the client as a return argument.
IUnknown * pUnkOuter,
//Pointer to whether object is or isn't part of
// an aggregate
REFIID riid, //Reference to the identifier of the interface
void ** ppvObject //Address of output variable that receives the
// interface pointer requested in riid
pUnkOuter [in] - If the object is being created as part of an aggregate, pointer to the controlling IUnknown interface of the aggregate. Otherwise, pUnkOuter must be NULL.
riid [in] - Reference to the identifier of the interface to be used to communicate with the newly created object. If pUnkOuter is NULL, this parameter is frequently the IID of the initializing interface; if pUnkOuter is non-NULL, riid must be IID_IUnknown (defined in the header as the IID for Unknown).
ppvObject [out] - Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObject contains the requested interface pointer. If the object does not support the interface specified in riid, the implementation must set *ppvObject to NULL.
CreateInstance Return Values
This method supports the standard return values E_UNEXPECTED, E_OUTOFMEMORY, and E_INVALIDARG, as well as the following:
- S_OK - The specified object was created.
- CLASS_E_NOAGGREGATION -
The pUnkOuter parameter was non-NULL and the object does not support aggregation.
- E_NOINTERFACE -
The object that ppvObject points to does not support the interface identified by riid.
CoGetClassObject function can be called to get an IClassFactory interface pointer to the class object, call the CreateInstance method of this interface to create new uninitialised objects.
However is is not always necessary to go through this process to create an object. To create a single uninitialized object, programmer can just call CoCreateInstance. OLE also provides numerous helper functions (with names of the form OleCreateXxx) to create compound document objects.
You have viewed 1 page out of 66. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.
Similar topics related to this section
COM DCOM Interview Questions and Answers :: ALL Interview .com
COM DCOM - COM DCOM Interview Questions
COM interview questions | TechInterviews
COM Interview Questions - CodeProject
Com Dcom Interview Questions - Com and Dcom in Asp Net
ATL Interview Questions and Answers :: ALL Interview .com
ActiveX Interview Questions and Answers :: ALL Interview .com
| #1 webmaster Wed 30 Apr/2014 01:20:44(GMT) || 0 || 0|
We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.
Your message goes here: