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: umisc.h
6//
7
8// ===========================================================================
9
10
11// Abstract:
12//
13// A collection of utility macros.
14//
15
16#ifndef UMISC_H
17#define UMISC_H
18
19#define COM_METHOD HRESULT STDMETHODCALLTYPE
20
21inline HRESULT HrFromWin32(DWORD dwWin32Error)
22{
23 return HRESULT_FROM_WIN32(dwWin32Error);
24}
25
26// Some helper #def's to safely Release, close & delete Objects under
27// failure conditions
28
29#define RELEASE(x) \
30 do \
31 { \
32 if (x) \
33 { \
34 IUnknown *punk = x; \
35 x = NULL; \
36 punk->Release(); \
37 } \
38 } while (0)
39
40
41#include "debugmacros.h"
42//
43// Good for verifying params withing range.
44//
45#define IfFalseGo(expr, HR) IfFailGo((expr) ? S_OK : (HR))
46
47// ----------------------------------------------------------------------------
48// Validation macros
49// Note that the Win32 APIs like IsBadReadPtr are banned
50//
51#define IsValidReadPtr(ptr, type) ((ptr)!=NULL)
52
53#define IsValidWritePtr(ptr, type) ((ptr)!=NULL)
54
55#define IsValidReadBufferPtr(ptr, type, len) ((ptr)!=NULL)
56
57#define IsValidWriteBufferPtr(ptr, type, len) ((ptr)!=NULL)
58
59#define IsValidInterfacePtr(ptr, type) ((ptr)!=NULL)
60
61#define IsValidCodePtr(ptr) ((ptr)!=NULL)
62
63#define IsValidStringPtr(ptr) ((ptr)!=NULL)
64
65#define IsValidIID(iid) TRUE
66
67#define IsValidCLSID(clsid) TRUE
68
69#endif
70