EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

#Previous question #Index of COM/DCOM Questions #Next question

Factory design

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.

IClassFactory::CreateInstance

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.

HRESULT CreateInstance(
  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
);

CreateInstance Parameters

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.

Calling CreateInstance

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.

 Vote 0

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)  Like 0 Unlike 0

Dear Users,

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.

Regards,
Webmaster

Your message goes here:

Name:Guest
Email:anonymous@unknown.com
My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
 
Note:
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.