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