| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | //***************************************************************************** |
| 5 | // ClassFactory.h |
| 6 | // |
| 7 | |
| 8 | // |
| 9 | // Class factories are used by the pluming in COM to activate new objects. |
| 10 | // This module contains the class factory code to instantiate the debugger |
| 11 | // objects described in RSPriv.h. |
| 12 | // |
| 13 | //***************************************************************************** |
| 14 | #ifndef __ClassFactory__h__ |
| 15 | #define __ClassFactory__h__ |
| 16 | |
| 17 | #include "rspriv.h" |
| 18 | |
| 19 | |
| 20 | // This typedef is for a function which will create a new instance of an object. |
| 21 | typedef HRESULT (STDMETHODCALLTYPE * PFN_CREATE_OBJ)(REFIID riid, void **ppvObject); |
| 22 | |
| 23 | |
| 24 | //***************************************************************************** |
| 25 | // One class factory object satifies all of our clsid's, to reduce overall |
| 26 | // code bloat. |
| 27 | //***************************************************************************** |
| 28 | class CClassFactory : |
| 29 | public IClassFactory |
| 30 | { |
| 31 | CClassFactory() { } // Can't use without data. |
| 32 | |
| 33 | public: |
| 34 | CClassFactory(PFN_CREATE_OBJ pfnCreateObject) |
| 35 | : m_cRef(1), m_pfnCreateObject(pfnCreateObject) |
| 36 | { } |
| 37 | |
| 38 | virtual ~CClassFactory() {} |
| 39 | |
| 40 | // |
| 41 | // IUnknown methods. |
| 42 | // |
| 43 | |
| 44 | virtual HRESULT STDMETHODCALLTYPE QueryInterface( |
| 45 | REFIID riid, |
| 46 | void **ppvObject); |
| 47 | |
| 48 | virtual ULONG STDMETHODCALLTYPE AddRef() |
| 49 | { |
| 50 | return (InterlockedIncrement(&m_cRef)); |
| 51 | } |
| 52 | |
| 53 | virtual ULONG STDMETHODCALLTYPE Release() |
| 54 | { |
| 55 | LONG cRef = InterlockedDecrement(&m_cRef); |
| 56 | if (cRef <= 0) |
| 57 | delete this; |
| 58 | return (cRef); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | // |
| 63 | // IClassFactory methods. |
| 64 | // |
| 65 | |
| 66 | virtual HRESULT STDMETHODCALLTYPE CreateInstance( |
| 67 | IUnknown *pUnkOuter, |
| 68 | REFIID riid, |
| 69 | void **ppvObject); |
| 70 | |
| 71 | virtual HRESULT STDMETHODCALLTYPE LockServer( |
| 72 | BOOL fLock); |
| 73 | |
| 74 | |
| 75 | private: |
| 76 | LONG m_cRef; // Reference count. |
| 77 | PFN_CREATE_OBJ m_pfnCreateObject; // Creation function for an instance. |
| 78 | }; |
| 79 | |
| 80 | |
| 81 | |
| 82 | #endif // __ClassFactory__h__ |
| 83 | |