The OpenD Programming Language

1 module core.sys.windows.com;
2 version (Windows):
3 
4 pragma(lib,"uuid");
5 
6 import core.atomic;
7 import core.sys.windows.windef /+: HRESULT, LONG, ULONG+/;
8 //import std.string;
9 
10 public import core.sys.windows.basetyps : GUID, IID, CLSID;
11 
12 public import core.sys.windows.objbase :
13     CLSCTX_INPROC, CLSCTX_ALL, CLSCTX_SERVER,
14     COINIT,
15     CoBuildVersion, StringFromGUID2,
16     CoInitialize, CoInitializeEx, CoUninitialize, CoGetCurrentProcess,
17     CoCreateInstance,
18     CoFreeLibrary, CoFreeAllLibraries, CoFreeUnusedLibraries;
19 
20 public import core.sys.windows.ole2ver : rmm, rup;
21 
22 public import core.sys.windows.unknwn : IUnknown, IClassFactory;
23 
24 public import core.sys.windows.winerror :
25     S_OK,
26     S_FALSE,
27     NOERROR,
28     E_NOTIMPL,
29     E_NOINTERFACE,
30     E_POINTER,
31     E_ABORT,
32     E_FAIL,
33     E_HANDLE,
34     CLASS_E_NOAGGREGATION,
35     E_OUTOFMEMORY,
36     E_INVALIDARG,
37     E_UNEXPECTED,
38     RPC_E_CHANGED_MODE;
39 
40 public import core.sys.windows.wtypes :
41     CLSCTX, OLECHAR, LPOLESTR, LPCOLESTR;
42 
43 alias CLSCTX_INPROC_SERVER     = CLSCTX.CLSCTX_INPROC_SERVER    ;
44 alias CLSCTX_INPROC_HANDLER    = CLSCTX.CLSCTX_INPROC_HANDLER   ;
45 alias CLSCTX_LOCAL_SERVER      = CLSCTX.CLSCTX_LOCAL_SERVER     ;
46 alias CLSCTX_INPROC_SERVER16   = CLSCTX.CLSCTX_INPROC_SERVER16  ;
47 alias CLSCTX_REMOTE_SERVER     = CLSCTX.CLSCTX_REMOTE_SERVER    ;
48 alias CLSCTX_INPROC_HANDLER16  = CLSCTX.CLSCTX_INPROC_HANDLER16 ;
49 alias CLSCTX_INPROC_SERVERX86  = CLSCTX.CLSCTX_INPROC_SERVERX86 ;
50 alias CLSCTX_INPROC_HANDLERX86 = CLSCTX.CLSCTX_INPROC_HANDLERX86;
51 
52 alias COINIT_APARTMENTTHREADED   = COINIT.COINIT_APARTMENTTHREADED;
53 alias COINIT_MULTITHREADED       = COINIT.COINIT_MULTITHREADED    ;
54 alias COINIT_DISABLE_OLE1DDE     = COINIT.COINIT_DISABLE_OLE1DDE  ;
55 alias COINIT_SPEED_OVER_MEMORY   = COINIT.COINIT_SPEED_OVER_MEMORY;
56 
57 public import core.sys.windows.uuid;
58 
59 extern (Windows)
60 {
61 
62 class ComObject : IUnknown
63 {
64 extern (Windows):
65     HRESULT QueryInterface(const(IID)* riid, void** ppv)
66     {
67         if (*riid == IID_IUnknown)
68         {
69             *ppv = cast(void*)cast(IUnknown)this;
70             AddRef();
71             return S_OK;
72         }
73         else
74         {   *ppv = null;
75             return E_NOINTERFACE;
76         }
77     }
78 
79     ULONG AddRef()
80     {
81         return atomicOp!"+="(*cast(shared)&count, 1);
82     }
83 
84     ULONG Release()
85     {
86         LONG lRef = atomicOp!"-="(*cast(shared)&count, 1);
87         if (lRef == 0)
88         {
89             // free object
90 
91             // If we delete this object, then the postinvariant called upon
92             // return from Release() will fail.
93             // Just let the GC reap it.
94             //delete this;
95 
96             return 0;
97         }
98         return cast(ULONG)lRef;
99     }
100 
101     LONG count = 0;             // object reference count
102 }
103 
104 }