1 // This module just contains things that are needed but aren't in std.c.windows.com. 2 // This code is public domain. 3 4 module dfl.internal.wincom; 5 6 private import dfl.internal.winapi; 7 8 9 version(WINE) 10 version = _dfl_needcom; 11 12 version(_dfl_needcom) 13 { 14 private import dfl.internal.dlib; 15 16 // Grabbed from std.c.windows.com: 17 18 alias WCHAR OLECHAR; 19 alias OLECHAR *LPOLESTR; 20 alias OLECHAR *LPCOLESTR; 21 22 enum 23 { 24 rmm = 23, // OLE 2 version number info 25 rup = 639, 26 } 27 28 enum : int 29 { 30 S_OK = 0, 31 S_FALSE = 0x00000001, 32 NOERROR = 0, 33 E_NOTIMPL = cast(int)0x80004001, 34 E_NOINTERFACE = cast(int)0x80004002, 35 E_POINTER = cast(int)0x80004003, 36 E_ABORT = cast(int)0x80004004, 37 E_FAIL = cast(int)0x80004005, 38 E_HANDLE = cast(int)0x80070006, 39 CLASS_E_NOAGGREGATION = cast(int)0x80040110, 40 E_OUTOFMEMORY = cast(int)0x8007000E, 41 E_INVALIDARG = cast(int)0x80070057, 42 E_UNEXPECTED = cast(int)0x8000FFFF, 43 } 44 45 struct GUID { // size is 16 46 align(1): 47 DWORD Data1; 48 WORD Data2; 49 WORD Data3; 50 BYTE Data4[8]; 51 } 52 53 enum 54 { 55 CLSCTX_INPROC_SERVER = 0x1, 56 CLSCTX_INPROC_HANDLER = 0x2, 57 CLSCTX_LOCAL_SERVER = 0x4, 58 CLSCTX_INPROC_SERVER16 = 0x8, 59 CLSCTX_REMOTE_SERVER = 0x10, 60 CLSCTX_INPROC_HANDLER16 = 0x20, 61 CLSCTX_INPROC_SERVERX86 = 0x40, 62 CLSCTX_INPROC_HANDLERX86 = 0x80, 63 64 CLSCTX_INPROC = (CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER), 65 CLSCTX_ALL = (CLSCTX_INPROC_SERVER| CLSCTX_INPROC_HANDLER| CLSCTX_LOCAL_SERVER), 66 CLSCTX_SERVER = (CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER), 67 } 68 69 alias GUID IID; 70 alias GUID CLSID; 71 72 extern (C) 73 { 74 extern IID IID_IUnknown; 75 extern IID IID_IClassFactory; 76 extern IID IID_IMarshal; 77 extern IID IID_IMallocSpy; 78 extern IID IID_IStdMarshalInfo; 79 extern IID IID_IExternalConnection; 80 extern IID IID_IMultiQI; 81 extern IID IID_IEnumUnknown; 82 extern IID IID_IBindCtx; 83 extern IID IID_IEnumMoniker; 84 extern IID IID_IRunnableObject; 85 extern IID IID_IRunningObjectTable; 86 extern IID IID_IPersist; 87 extern IID IID_IPersistStream; 88 extern IID IID_IMoniker; 89 extern IID IID_IROTData; 90 extern IID IID_IEnumString; 91 extern IID IID_ISequentialStream; 92 extern IID IID_IStream; 93 extern IID IID_IEnumSTATSTG; 94 extern IID IID_IStorage; 95 extern IID IID_IPersistFile; 96 extern IID IID_IPersistStorage; 97 extern IID IID_ILockBytes; 98 extern IID IID_IEnumFORMATETC; 99 extern IID IID_IEnumSTATDATA; 100 extern IID IID_IRootStorage; 101 extern IID IID_IAdviseSink; 102 extern IID IID_IAdviseSink2; 103 extern IID IID_IDataObject; 104 extern IID IID_IDataAdviseHolder; 105 extern IID IID_IMessageFilter; 106 extern IID IID_IRpcChannelBuffer; 107 extern IID IID_IRpcProxyBuffer; 108 extern IID IID_IRpcStubBuffer; 109 extern IID IID_IPSFactoryBuffer; 110 extern IID IID_IPropertyStorage; 111 extern IID IID_IPropertySetStorage; 112 extern IID IID_IEnumSTATPROPSTG; 113 extern IID IID_IEnumSTATPROPSETSTG; 114 extern IID IID_IFillLockBytes; 115 extern IID IID_IProgressNotify; 116 extern IID IID_ILayoutStorage; 117 extern IID GUID_NULL; 118 extern IID IID_IRpcChannel; 119 extern IID IID_IRpcStub; 120 extern IID IID_IStubManager; 121 extern IID IID_IRpcProxy; 122 extern IID IID_IProxyManager; 123 extern IID IID_IPSFactory; 124 extern IID IID_IInternalMoniker; 125 extern IID IID_IDfReserved1; 126 extern IID IID_IDfReserved2; 127 extern IID IID_IDfReserved3; 128 extern IID IID_IStub; 129 extern IID IID_IProxy; 130 extern IID IID_IEnumGeneric; 131 extern IID IID_IEnumHolder; 132 extern IID IID_IEnumCallback; 133 extern IID IID_IOleManager; 134 extern IID IID_IOlePresObj; 135 extern IID IID_IDebug; 136 extern IID IID_IDebugStream; 137 extern IID IID_StdOle; 138 extern IID IID_ICreateTypeInfo; 139 extern IID IID_ICreateTypeInfo2; 140 extern IID IID_ICreateTypeLib; 141 extern IID IID_ICreateTypeLib2; 142 extern IID IID_IDispatch; 143 extern IID IID_IEnumVARIANT; 144 extern IID IID_ITypeComp; 145 extern IID IID_ITypeInfo; 146 extern IID IID_ITypeInfo2; 147 extern IID IID_ITypeLib; 148 extern IID IID_ITypeLib2; 149 extern IID IID_ITypeChangeEvents; 150 extern IID IID_IErrorInfo; 151 extern IID IID_ICreateErrorInfo; 152 extern IID IID_ISupportErrorInfo; 153 extern IID IID_IOleAdviseHolder; 154 extern IID IID_IOleCache; 155 extern IID IID_IOleCache2; 156 extern IID IID_IOleCacheControl; 157 extern IID IID_IParseDisplayName; 158 extern IID IID_IOleContainer; 159 extern IID IID_IOleClientSite; 160 extern IID IID_IOleObject; 161 extern IID IID_IOleWindow; 162 extern IID IID_IOleLink; 163 extern IID IID_IOleItemContainer; 164 extern IID IID_IOleInPlaceUIWindow; 165 extern IID IID_IOleInPlaceActiveObject; 166 extern IID IID_IOleInPlaceFrame; 167 extern IID IID_IOleInPlaceObject; 168 extern IID IID_IOleInPlaceSite; 169 extern IID IID_IContinue; 170 extern IID IID_IViewObject; 171 extern IID IID_IViewObject2; 172 extern IID IID_IDropSource; 173 extern IID IID_IDropTarget; 174 extern IID IID_IEnumOLEVERB; 175 } 176 177 extern (Windows) 178 { 179 180 export 181 { 182 DWORD CoBuildVersion(); 183 184 int StringFromGUID2(GUID *rguid, LPOLESTR lpsz, int cbMax); 185 186 /* init/uninit */ 187 188 HRESULT CoInitialize(LPVOID pvReserved); 189 void CoUninitialize(); 190 DWORD CoGetCurrentProcess(); 191 192 193 HRESULT CoCreateInstance(CLSID *rclsid, IUnknown UnkOuter, 194 DWORD dwClsContext, IID* riid, void* ppv); 195 196 //HINSTANCE CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree); 197 void CoFreeLibrary(HINSTANCE hInst); 198 void CoFreeAllLibraries(); 199 void CoFreeUnusedLibraries(); 200 } 201 202 interface IUnknown 203 { 204 HRESULT QueryInterface(IID* riid, void** pvObject); 205 ULONG AddRef(); 206 ULONG Release(); 207 } 208 209 interface IClassFactory : IUnknown 210 { 211 HRESULT CreateInstance(IUnknown UnkOuter, IID* riid, void** pvObject); 212 HRESULT LockServer(BOOL fLock); 213 } 214 215 class ComObject : IUnknown 216 { 217 extern (Windows): 218 HRESULT QueryInterface(IID* riid, void** ppv) 219 { 220 if (*riid == IID_IUnknown) 221 { 222 *ppv = cast(void*)cast(IUnknown)this; 223 AddRef(); 224 return S_OK; 225 } 226 else 227 { *ppv = null; 228 return E_NOINTERFACE; 229 } 230 } 231 232 ULONG AddRef() 233 { 234 return InterlockedIncrement(&count); 235 } 236 237 ULONG Release() 238 { 239 LONG lRef = InterlockedDecrement(&count); 240 if (lRef == 0) 241 { 242 // free object 243 244 // If we delete this object, then the postinvariant called upon 245 // return from Release() will fail. 246 // Just let the GC reap it. 247 //delete this; 248 249 return 0; 250 } 251 return cast(ULONG)lRef; 252 } 253 254 LONG count = 0; // object reference count 255 } 256 257 } 258 } 259 else 260 { 261 public import std.c.windows.com; 262 } 263 264 265 extern(C) 266 { 267 extern IID IID_IPicture; 268 269 version(REDEFINE_UUIDS) 270 { 271 // These are needed because uuid.lib is broken in DMC 8.46. 272 IID _IID_IUnknown= { 0, 0, 0, [ 192, 0, 0, 0, 0, 0, 0, 70] }; 273 IID _IID_IDataObject = { 270, 0, 0, [192, 0, 0, 0, 0, 0, 0, 70 ] }; 274 IID _IID_IPicture = { 2079852928, 48946, 4122, [139, 187, 0, 170, 0, 48, 12, 171] }; 275 IID _IID_ISequentialStream = { 208878128, 10780, 4558, [ 173, 229, 0, 170, 0, 68, 119, 61 ] }; 276 IID _IID_IStream = { 12, 0, 0, [ 192, 0, 0, 0, 0, 0, 0, 70 ] }; 277 IID _IID_IDropTarget = { 290, 0, 0, [ 192, 0, 0, 0, 0, 0, 0, 70 ] }; 278 IID _IID_IDropSource = { 289, 0, 0, [ 192, 0, 0, 0, 0, 0, 0, 70 ] }; 279 IID _IID_IEnumFORMATETC = { 259, 0, 0, [ 192, 0, 0, 0, 0, 0, 0, 70 ] }; 280 } 281 else 282 { 283 alias IID_IUnknown _IID_IUnknown; 284 alias IID_IDataObject _IID_IDataObject; 285 alias IID_IPicture _IID_IPicture; 286 alias IID_ISequentialStream _IID_ISequentialStream; 287 alias IID_IStream _IID_IStream; 288 alias IID_IDropTarget _IID_IDropTarget; 289 alias IID_IDropSource _IID_IDropSource; 290 alias IID_IEnumFORMATETC _IID_IEnumFORMATETC; 291 } 292 } 293 294 295 extern(Windows): 296 297 interface ISequentialStream: IUnknown 298 { 299 extern(Windows): 300 HRESULT Read(void* pv, ULONG cb, ULONG* pcbRead); 301 HRESULT Write(void* pv, ULONG cb, ULONG* pcbWritten); 302 } 303 304 305 /// STREAM_SEEK 306 enum: DWORD 307 { 308 STREAM_SEEK_SET = 0, 309 STREAM_SEEK_CUR = 1, 310 STREAM_SEEK_END = 2, 311 } 312 alias DWORD STREAM_SEEK; 313 314 315 // TODO: implement the enum`s used here. 316 struct STATSTG 317 { 318 LPWSTR pwcsName; 319 DWORD type; 320 ULARGE_INTEGER cbSize; 321 FILETIME mtime; 322 FILETIME ctime; 323 FILETIME atime; 324 DWORD grfMode; 325 DWORD grfLocksSupported; 326 CLSID clsid; 327 DWORD grfStateBits; 328 DWORD reserved; 329 } 330 331 332 interface IStream: ISequentialStream 333 { 334 extern(Windows): 335 HRESULT Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition); 336 HRESULT SetSize(ULARGE_INTEGER libNewSize); 337 HRESULT CopyTo(IStream pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten); 338 HRESULT Commit(DWORD grfCommitFlags); 339 HRESULT Revert(); 340 HRESULT LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType); 341 HRESULT UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType); 342 HRESULT Stat(STATSTG* pstatstg, DWORD grfStatFlag); 343 HRESULT Clone(IStream* ppstm); 344 } 345 alias IStream* LPSTREAM; 346 347 348 alias UINT OLE_HANDLE; 349 350 alias LONG OLE_XPOS_HIMETRIC; 351 352 alias LONG OLE_YPOS_HIMETRIC; 353 354 alias LONG OLE_XSIZE_HIMETRIC; 355 356 alias LONG OLE_YSIZE_HIMETRIC; 357 358 359 interface IPicture: IUnknown 360 { 361 extern(Windows): 362 HRESULT get_Handle(OLE_HANDLE* phandle); 363 HRESULT get_hPal(OLE_HANDLE* phpal); 364 HRESULT get_Type(short* ptype); 365 HRESULT get_Width(OLE_XSIZE_HIMETRIC* pwidth); 366 HRESULT get_Height(OLE_YSIZE_HIMETRIC* pheight); 367 HRESULT Render(HDC hdc, int x, int y, int cx, int cy, OLE_XPOS_HIMETRIC xSrc, OLE_YPOS_HIMETRIC ySrc, OLE_XSIZE_HIMETRIC cxSrc, OLE_YSIZE_HIMETRIC cySrc, LPCRECT prcWBounds); 368 HRESULT set_hPal(OLE_HANDLE hpal); 369 HRESULT get_CurDC(HDC* phdcOut); 370 HRESULT SelectPicture(HDC hdcIn, HDC* phdcOut, OLE_HANDLE* phbmpOut); 371 HRESULT get_KeepOriginalFormat(BOOL* pfkeep); 372 HRESULT put_KeepOriginalFormat(BOOL keep); 373 HRESULT PictureChanged(); 374 HRESULT SaveAsFile(IStream pstream, BOOL fSaveMemCopy, LONG* pcbSize); 375 HRESULT get_Attributes(DWORD* pdwAttr); 376 } 377 378 struct DVTARGETDEVICE 379 { 380 DWORD tdSize; 381 WORD tdDriverNameOffset; 382 WORD tdDeviceNameOffset; 383 WORD tdPortNameOffset; 384 WORD tdExtDevmodeOffset; 385 BYTE[1] tdData; 386 } 387 388 389 struct FORMATETC 390 { 391 CLIPFORMAT cfFormat; 392 DVTARGETDEVICE* ptd; 393 DWORD dwAspect; 394 LONG lindex; 395 DWORD tymed; 396 } 397 alias FORMATETC* LPFORMATETC; 398 399 400 struct STATDATA 401 { 402 FORMATETC formatetc; 403 DWORD grfAdvf; 404 IAdviseSink pAdvSink; 405 DWORD dwConnection; 406 } 407 408 409 struct STGMEDIUM 410 { 411 DWORD tymed; 412 union //u 413 { 414 HBITMAP hBitmap; 415 //HMETAFILEPICT hMetaFilePict; 416 HENHMETAFILE hEnhMetaFile; 417 HGLOBAL hGlobal; 418 LPOLESTR lpszFileName; 419 IStream pstm; 420 //IStorage pstg; 421 } 422 IUnknown pUnkForRelease; 423 } 424 alias STGMEDIUM* LPSTGMEDIUM; 425 426 427 interface IDataObject: IUnknown 428 { 429 extern(Windows): 430 HRESULT GetData(FORMATETC* pFormatetc, STGMEDIUM* pmedium); 431 HRESULT GetDataHere(FORMATETC* pFormatetc, STGMEDIUM* pmedium); 432 HRESULT QueryGetData(FORMATETC* pFormatetc); 433 HRESULT GetCanonicalFormatEtc(FORMATETC* pFormatetcIn, FORMATETC* pFormatetcOut); 434 HRESULT SetData(FORMATETC* pFormatetc, STGMEDIUM* pmedium, BOOL fRelease); 435 HRESULT EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC* ppenumFormatetc); 436 HRESULT DAdvise(FORMATETC* pFormatetc, DWORD advf, IAdviseSink pAdvSink, DWORD* pdwConnection); 437 HRESULT DUnadvise(DWORD dwConnection); 438 HRESULT EnumDAdvise(IEnumSTATDATA* ppenumAdvise); 439 } 440 441 442 interface IDropSource: IUnknown 443 { 444 extern(Windows): 445 HRESULT QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState); 446 HRESULT GiveFeedback(DWORD dwEffect); 447 } 448 449 450 interface IDropTarget: IUnknown 451 { 452 extern(Windows): 453 HRESULT DragEnter(IDataObject pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect); 454 HRESULT DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect); 455 HRESULT DragLeave(); 456 HRESULT Drop(IDataObject pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect); 457 } 458 459 460 interface IEnumFORMATETC: IUnknown 461 { 462 extern(Windows): 463 HRESULT Next(ULONG celt, FORMATETC* rgelt, ULONG* pceltFetched); 464 HRESULT Skip(ULONG celt); 465 HRESULT Reset(); 466 HRESULT Clone(IEnumFORMATETC* ppenum); 467 } 468 469 470 interface IEnumSTATDATA: IUnknown 471 { 472 extern(Windows): 473 HRESULT Next(ULONG celt, STATDATA* rgelt, ULONG* pceltFetched); 474 HRESULT Skip(ULONG celt); 475 HRESULT Reset(); 476 HRESULT Clone(IEnumSTATDATA* ppenum); 477 } 478 479 480 interface IAdviseSink: IUnknown 481 { 482 // TODO: finish. 483 } 484 485 486 interface IMalloc: IUnknown 487 { 488 extern(Windows): 489 void* Alloc(ULONG cb); 490 void* Realloc(void *pv, ULONG cb); 491 void Free(void* pv); 492 ULONG GetSize(void* pv); 493 int DidAlloc(void* pv); 494 void HeapMinimize(); 495 } 496 // Since an interface is a pointer.. 497 alias IMalloc PMALLOC; 498 alias IMalloc LPMALLOC; 499 500 501 LONG MAP_LOGHIM_TO_PIX(LONG x, LONG logpixels) 502 { 503 return MulDiv(logpixels, x, 2540); 504 } 505 506 507 enum: DWORD 508 { 509 DVASPECT_CONTENT = 1, 510 DVASPECT_THUMBNAIL = 2, 511 DVASPECT_ICON = 4, 512 DVASPECT_DOCPRINT = 8, 513 } 514 alias DWORD DVASPECT; 515 516 517 enum: DWORD 518 { 519 TYMED_HGLOBAL = 1, 520 TYMED_FILE = 2, 521 TYMED_ISTREAM = 4, 522 TYMED_ISTORAGE = 8, 523 TYMED_GDI = 16, 524 TYMED_MFPICT = 32, 525 TYMED_ENHMF = 64, 526 TYMED_NULL = 0 527 } 528 alias DWORD TYMED; 529 530 531 enum 532 { 533 DATADIR_GET = 1, 534 } 535 536 537 enum: HRESULT 538 { 539 DRAGDROP_S_DROP = 0x00040100, 540 DRAGDROP_S_CANCEL = 0x00040101, 541 DRAGDROP_S_USEDEFAULTCURSORS = 0x00040102, 542 V_E_LINDEX = cast(HRESULT)0x80040068, 543 STG_E_MEDIUMFULL = cast(HRESULT)0x80030070, 544 STG_E_INVALIDFUNCTION = cast(HRESULT)0x80030001, 545 DV_E_TYMED = cast(HRESULT)0x80040069, 546 DV_E_DVASPECT = cast(HRESULT)0x8004006B, 547 DV_E_FORMATETC = cast(HRESULT)0x80040064, 548 DV_E_LINDEX = cast(HRESULT)0x80040068, 549 DRAGDROP_E_ALREADYREGISTERED = cast(HRESULT)0x80040101, 550 } 551 552 553 alias HRESULT WINOLEAPI; 554 555 556 WINOLEAPI OleInitialize(LPVOID pvReserved); 557 WINOLEAPI DoDragDrop(IDataObject pDataObject, IDropSource pDropSource, DWORD dwOKEffect, DWORD* pdwEffect); 558 WINOLEAPI RegisterDragDrop(HWND hwnd, IDropTarget pDropTarget); 559 WINOLEAPI RevokeDragDrop(HWND hwnd); 560 WINOLEAPI OleGetClipboard(IDataObject* ppDataObj); 561 WINOLEAPI OleSetClipboard(IDataObject pDataObj); 562 WINOLEAPI OleFlushClipboard(); 563 WINOLEAPI CreateStreamOnHGlobal(HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPSTREAM ppstm); 564 WINOLEAPI OleLoadPicture(IStream pStream, LONG lSize, BOOL fRunmode, IID* riid, void** ppv); 565