PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Visual Studio 2008/CppExeCOMServer/ClassFactory.h

#
C++ Header | 63 lines | 17 code | 8 blank | 38 comment | 0 complexity | 21d9f70faa29820a16a2f005a1707916 MD5 | raw file
 1/****************************** Module Header ******************************\
 2Module Name:  ClassFactory.h
 3Project:      CppExeCOMServer
 4Copyright (c) Microsoft Corporation.
 5
 6The file declares the class factory for the SimpleObject COM class. A class 
 7factory (aka a class object) is a component whose main purpose is to create 
 8other components. It provides many controls over the creation process of the 
 9component. When a client uses a CLSID to request the creation of an object 
10instance, the first step is creation of a class factory, an intermediate 
11object that contains an implementation of the methods of the IClassFactory 
12interface. While COM provides several instance creation functions, the first 
13step in the implementation of these functions is always the creation of a 
14class factory. For example, CoCreateInstance provides a wrapper over a 
15CoGetClassObject and CreateInstance method of IClassFactory interface. 
16CoCreateInstance internally creates class factory for the specified CLSID, 
17gets the IClassFactory interface pointer, and then creates the component by 
18calling CreateInstance on IClassFactory interface pointer and then returns 
19the requested interface pointer to the client by calling QueryInterface 
20method in the CreateInstance method of IClassFactory.
21
22The class factory implements the IClassFactory interface. The class factory 
23object must implement these two methods of IClassFactory to support the 
24object creation.
25
26    IFACEMETHODIMP CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppv);
27    IFACEMETHODIMP LockServer(BOOL fLock);
28
29This source is subject to the Microsoft Public License.
30See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
31All other rights reserved.
32
33THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
34EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
35WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
36\***************************************************************************/
37
38#pragma once
39
40#include <unknwn.h>     // For IClassFactory
41#include <windows.h>
42
43
44class ClassFactory : public IClassFactory
45{
46public:
47    // IUnknown
48    IFACEMETHODIMP QueryInterface(REFIID riid, void **ppv);
49    IFACEMETHODIMP_(ULONG) AddRef();
50    IFACEMETHODIMP_(ULONG) Release();
51
52    // IClassFactory
53    IFACEMETHODIMP CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppv);
54    IFACEMETHODIMP LockServer(BOOL fLock);
55
56    ClassFactory();
57
58protected:
59    ~ClassFactory();
60
61private:
62    long m_cRef;
63};