CFPlugInCOM.h
1 /* CFPlugInCOM.h 2 Copyright (c) 1999-2019, Apple Inc. and the Swift project authors 3 4 Portions Copyright (c) 2014-2019, Apple Inc. and the Swift project authors 5 Licensed under Apache License v2.0 with Runtime Library Exception 6 See http://swift.org/LICENSE.txt for license information 7 See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 8 */ 9 10 #if !defined(__COREFOUNDATION_CFPLUGINCOM__) 11 #define __COREFOUNDATION_CFPLUGINCOM__ 1 12 13 #include <CoreFoundation/CFPlugIn.h> 14 15 CF_EXTERN_C_BEGIN 16 17 /* ================= IUnknown definition (C struct) ================= */ 18 19 /* All interface structs must have an IUnknownStruct at the beginning. */ 20 /* The _reserved field is part of the Microsoft COM binary standard on Macintosh. */ 21 /* You can declare new C struct interfaces by defining a new struct that includes "IUNKNOWN_C_GUTS;" before the first field of the struct. */ 22 23 #if TARGET_OS_WIN32 24 #define NOMINMAX 25 #define VC_EXTRALEAN 26 #define WIN32_LEAN_AND_MEAN 27 #include <Windows.h> 28 #else 29 typedef SInt32 HRESULT; 30 typedef UInt32 ULONG; 31 typedef void *LPVOID; 32 typedef CFUUIDBytes REFIID; 33 #endif 34 35 #define SUCCEEDED(Status) ((HRESULT)(Status) >= 0) 36 #define FAILED(Status) ((HRESULT)(Status)<0) 37 38 /* Macros for more detailed HRESULT analysis */ 39 #define IS_ERROR(Status) ((unsigned long)(Status) >> 31 == SEVERITY_ERROR) 40 #define HRESULT_CODE(hr) ((hr) & 0xFFFF) 41 #define HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff) 42 #define HRESULT_SEVERITY(hr) (((hr) >> 31) & 0x1) 43 #define SEVERITY_SUCCESS 0 44 #define SEVERITY_ERROR 1 45 46 /* Creating an HRESULT from its component pieces */ 47 #define MAKE_HRESULT(sev,fac,code) ((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) ) 48 49 /* Pre-defined success HRESULTS */ 50 #define S_OK ((HRESULT)0x00000000L) 51 #define S_FALSE ((HRESULT)0x00000001L) 52 53 /* Common error HRESULTS */ 54 #define E_UNEXPECTED ((HRESULT)0x8000FFFFL) 55 #define E_NOTIMPL ((HRESULT)0x80000001L) 56 #define E_OUTOFMEMORY ((HRESULT)0x80000002L) 57 #define E_INVALIDARG ((HRESULT)0x80000003L) 58 #define E_NOINTERFACE ((HRESULT)0x80000004L) 59 #define E_POINTER ((HRESULT)0x80000005L) 60 #define E_HANDLE ((HRESULT)0x80000006L) 61 #define E_ABORT ((HRESULT)0x80000007L) 62 #define E_FAIL ((HRESULT)0x80000008L) 63 #define E_ACCESSDENIED ((HRESULT)0x80000009L) 64 65 /* This macro should be used when defining all interface functions (as it is for the IUnknown functions below). */ 66 #define STDMETHODCALLTYPE 67 68 /* The __RPC_FAR macro is for COM source compatibility only. This macro is used a lot in COM interface definitions. If your CFPlugIn interfaces need to be COM interfaces as well, you can use this macro to get better source compatibility. It is not used in the IUnknown definition below, because when doing COM, you will be using the Microsoft supplied IUnknown interface anyway. */ 69 #define __RPC_FAR 70 71 /* The IUnknown interface */ 72 #define IUnknownUUID CFUUIDGetConstantUUIDWithBytes(kCFAllocatorSystemDefault, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46) 73 74 #if __clang__ 75 #define __PRAGMA_PUSH_NO_NULLABILITY_COMPLETENESS_WARNINGS _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wnullability-completeness\"") 76 #define __PRAGMA_POP_NO_NULLABILITY_COMPLETENESS_WARNINGS _Pragma("clang diagnostic pop") 77 #else 78 #define __PRAGMA_PUSH_NO_NULLABILITY_COMPLETENESS_WARNINGS 79 #define __PRAGMA_POP_NO_NULLABILITY_COMPLETENESS_WARNINGS 80 #endif 81 82 #define IUNKNOWN_C_GUTS \ 83 __PRAGMA_PUSH_NO_NULLABILITY_COMPLETENESS_WARNINGS \ 84 void *_reserved; \ 85 HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv); \ 86 ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer); \ 87 ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer) \ 88 __PRAGMA_POP_NO_NULLABILITY_COMPLETENESS_WARNINGS 89 90 typedef struct IUnknownVTbl { 91 IUNKNOWN_C_GUTS; 92 } IUnknownVTbl; 93 94 CF_EXTERN_C_END 95 96 97 /* C++ specific stuff */ 98 #if defined(__cplusplus) 99 /* ================= IUnknown definition (C++ class) ================= */ 100 101 /* This is a definition of IUnknown as a pure abstract virtual C++ class. This class will work only with compilers that can produce COM-compatible object layouts for C++ classes. egcs can not do this. MetroWerks can do this (if you subclass from __comobject) */ 102 103 class IUnknown 104 #if defined(__MWERKS__) && TARGET_OS_WIN32 105 : __comobject 106 #endif 107 { 108 public: 109 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv) = 0; 110 virtual ULONG STDMETHODCALLTYPE AddRef(void) = 0; 111 virtual ULONG STDMETHODCALLTYPE Release(void) = 0; 112 }; 113 114 #endif /* __cplusplus */ 115 116 #endif /* ! __COREFOUNDATION_CFPLUGINCOM__ */ 117