|
| 1 | + |
| 2 | +/* Server for IHello |
| 3 | + * Heavily modified from: |
| 4 | + */ |
| 5 | +/* |
| 6 | + * SELFREG.CPP |
| 7 | + * Server Self-Registrtation Utility, Chapter 5 |
| 8 | + * |
| 9 | + * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved |
| 10 | + * |
| 11 | + * Kraig Brockschmidt, Microsoft |
| 12 | + |
| 13 | + * Compuserve: >INTERNET:[email protected] |
| 14 | + */ |
| 15 | + |
| 16 | +// From an example from "Inside OLE" Copyright Microsoft |
| 17 | + |
| 18 | +import core.stdc.stdio; |
| 19 | +import core.stdc.stdlib; |
| 20 | +import std.string; |
| 21 | +import core.sys.windows.com; |
| 22 | +import core.sys.windows.windef; |
| 23 | + |
| 24 | +GUID CLSID_Hello = { 0x30421140, 0, 0, [0xC0, 0, 0, 0, 0, 0, 0, 0x46] }; |
| 25 | +GUID IID_IHello = { 0x00421140, 0, 0, [0xC0, 0, 0, 0, 0, 0, 0, 0x46] }; |
| 26 | + |
| 27 | +interface IHello : IUnknown |
| 28 | +{ |
| 29 | + extern (Windows) : |
| 30 | + int Print(); |
| 31 | +} |
| 32 | + |
| 33 | +// Type for an object-destroyed callback |
| 34 | +alias void function() PFNDESTROYED; |
| 35 | + |
| 36 | +/* |
| 37 | + * The class definition for an object that singly implements |
| 38 | + * IHello in D. |
| 39 | + */ |
| 40 | +class CHello : ComObject, IHello |
| 41 | +{ |
| 42 | +protected: |
| 43 | + IUnknown m_pUnkOuter; // Controlling unknown |
| 44 | + |
| 45 | + PFNDESTROYED m_pfnDestroy; // To call on closure |
| 46 | + |
| 47 | + /* |
| 48 | + * pUnkOuter LPUNKNOWN of a controlling unknown. |
| 49 | + * pfnDestroy PFNDESTROYED to call when an object |
| 50 | + * is destroyed. |
| 51 | + */ |
| 52 | + public this(IUnknown pUnkOuter, PFNDESTROYED pfnDestroy) |
| 53 | + { |
| 54 | + m_pUnkOuter = pUnkOuter; |
| 55 | + m_pfnDestroy = pfnDestroy; |
| 56 | + } |
| 57 | + |
| 58 | + ~this() |
| 59 | + { |
| 60 | + printf("CHello.~this()\n"); |
| 61 | + } |
| 62 | + |
| 63 | + extern (Windows) : |
| 64 | + /* |
| 65 | + * Performs any initialization of a CHello that's prone to failure |
| 66 | + * that we also use internally before exposing the object outside. |
| 67 | + * Return Value: |
| 68 | + * BOOL true if the function is successful, |
| 69 | + * false otherwise. |
| 70 | + */ |
| 71 | + |
| 72 | +public: |
| 73 | + BOOL Init() |
| 74 | + { |
| 75 | + printf("CHello.Init()\n"); |
| 76 | + return true; |
| 77 | + } |
| 78 | + |
| 79 | +public: |
| 80 | + override HRESULT QueryInterface(const (IID)*riid, LPVOID *ppv) |
| 81 | + { |
| 82 | + printf("CHello.QueryInterface()\n"); |
| 83 | + |
| 84 | + if (IID_IUnknown == *riid) |
| 85 | + *ppv = cast(void*) cast(IUnknown) this; |
| 86 | + else if (IID_IHello == *riid) |
| 87 | + *ppv = cast(void*) cast(IHello) this; |
| 88 | + else |
| 89 | + { |
| 90 | + *ppv = null; |
| 91 | + return E_NOINTERFACE; |
| 92 | + } |
| 93 | + |
| 94 | + AddRef(); |
| 95 | + return NOERROR; |
| 96 | + } |
| 97 | + |
| 98 | + override ULONG Release() |
| 99 | + { |
| 100 | + printf("CHello.Release()\n"); |
| 101 | + |
| 102 | + if (0 != --count) |
| 103 | + return count; |
| 104 | + |
| 105 | + /* |
| 106 | + * Tell the housing that an object is going away so it can |
| 107 | + * shut down if appropriate. |
| 108 | + */ |
| 109 | + printf("CHello Destroy()\n"); |
| 110 | + |
| 111 | + if (m_pfnDestroy) |
| 112 | + (*m_pfnDestroy)(); |
| 113 | + |
| 114 | + // delete this; |
| 115 | + return 0; |
| 116 | + } |
| 117 | + |
| 118 | + // IHello members |
| 119 | + override HRESULT Print() |
| 120 | + { |
| 121 | + printf("CHello.Print()\n"); |
| 122 | + return NOERROR; |
| 123 | + } |
| 124 | +} |
0 commit comments