| 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 | // File: ClassFactory.h |
| 6 | // |
| 7 | |
| 8 | // =========================================================================== |
| 9 | |
| 10 | //***************************************************************************** |
| 11 | // ClassFactory.h |
| 12 | // |
| 13 | // Class factories are used by the pluming in COM to activate new objects. |
| 14 | // This module contains the class factory code to instantiate the |
| 15 | // ISymUnmanaged Reader,Writer and Binder |
| 16 | //***************************************************************************** |
| 17 | #ifndef __ILDBClassFactory__h__ |
| 18 | #define __ILDBClassFactory__h__ |
| 19 | |
| 20 | // This typedef is for a function which will create a new instance of an object. |
| 21 | typedef HRESULT (* PFN_CREATE_OBJ)(REFIID riid, void**ppvObject); |
| 22 | |
| 23 | //***************************************************************************** |
| 24 | // This structure is used to declare a global list of coclasses. The class |
| 25 | // factory object is created with a pointer to the correct one of these, so |
| 26 | // that when create instance is called, it can be created. |
| 27 | //***************************************************************************** |
| 28 | struct COCLASS_REGISTER |
| 29 | { |
| 30 | const GUID *pClsid; // Class ID of the coclass. |
| 31 | LPCWSTR szProgID; // Prog ID of the class. |
| 32 | PFN_CREATE_OBJ pfnCreateObject; // Creation function for an instance. |
| 33 | }; |
| 34 | |
| 35 | |
| 36 | |
| 37 | //***************************************************************************** |
| 38 | // One class factory object satifies all of our clsid's, to reduce overall |
| 39 | // code bloat. |
| 40 | //***************************************************************************** |
| 41 | class CIldbClassFactory : |
| 42 | public IClassFactory |
| 43 | { |
| 44 | CIldbClassFactory() { } // Can't use without data. |
| 45 | |
| 46 | public: |
| 47 | CIldbClassFactory(const COCLASS_REGISTER *pCoClass) |
| 48 | : m_cRef(1), m_pCoClass(pCoClass) |
| 49 | { } |
| 50 | |
| 51 | virtual ~CIldbClassFactory() {} |
| 52 | |
| 53 | // |
| 54 | // IUnknown methods. |
| 55 | // |
| 56 | |
| 57 | virtual HRESULT STDMETHODCALLTYPE QueryInterface( |
| 58 | REFIID riid, |
| 59 | void **ppvObject); |
| 60 | |
| 61 | virtual ULONG STDMETHODCALLTYPE AddRef() |
| 62 | { |
| 63 | return InterlockedIncrement(&m_cRef); |
| 64 | } |
| 65 | |
| 66 | virtual ULONG STDMETHODCALLTYPE Release() |
| 67 | { |
| 68 | LONG cRef = InterlockedDecrement(&m_cRef); |
| 69 | if (cRef <= 0) |
| 70 | DELETE(this); |
| 71 | return (cRef); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | // |
| 76 | // IClassFactory methods. |
| 77 | // |
| 78 | |
| 79 | virtual HRESULT STDMETHODCALLTYPE CreateInstance( |
| 80 | IUnknown *pUnkOuter, |
| 81 | REFIID riid, |
| 82 | void **ppvObject); |
| 83 | |
| 84 | virtual HRESULT STDMETHODCALLTYPE LockServer( |
| 85 | BOOL fLock); |
| 86 | |
| 87 | |
| 88 | private: |
| 89 | LONG m_cRef; // Reference count. |
| 90 | const COCLASS_REGISTER *m_pCoClass; // The class we belong to. |
| 91 | }; |
| 92 | |
| 93 | |
| 94 | |
| 95 | #endif // __ClassFactory__h__ |
| 96 | |