summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorJames Ross-Gowan <rossymiles@gmail.com>2017-01-29 23:59:24 +1100
committerJames Ross-Gowan <rossymiles@gmail.com>2017-01-30 00:22:30 +1100
commit9692814502223574b575931d32ddd458b9476bb6 (patch)
tree8a86cb132d6b03e46a28fa18218be1da20607ea6 /osdep
parenta6d29494ca6e45b66570deda99c2eef79f72d16c (diff)
downloadmpv-9692814502223574b575931d32ddd458b9476bb6.tar.bz2
mpv-9692814502223574b575931d32ddd458b9476bb6.tar.xz
win32: add COM-specific SAFE_RELEASE to windows_utils.h
See: https://msdn.microsoft.com/en-us/library/windows/desktop/dd743946.aspx Microsoft example code often uses a SAFE_RELEASE macro like the one in the above link. This makes it easier to avoid errors when releasing COM interfaces. It also reduces noise in COM-heavy code. ao_wasapi.h also had a macro called SAFE_RELEASE, though unlike the version above, its SAFE_RELEASE macro accepted a second parameter which allowed it to destroy arbitrary objects other than just COM interfaces. This renames ao_wasapi's SAFE_RELEASE to SAFE_DESTROY, which should more accurately reflect what it does and prevent confusion with the Microsoft version.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/windows_utils.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/osdep/windows_utils.h b/osdep/windows_utils.h
index 6c750ded2a..a20a558709 100644
--- a/osdep/windows_utils.h
+++ b/osdep/windows_utils.h
@@ -20,6 +20,10 @@
#include <windows.h>
+// Conditionally release a COM interface and set the pointer to NULL
+#define SAFE_RELEASE(u) \
+ do { if ((u) != NULL) (u)->lpVtbl->Release(u); (u) = NULL; } while(0)
+
char *mp_GUID_to_str_buf(char *buf, size_t buf_size, const GUID *guid);
#define mp_GUID_to_str(guid) mp_GUID_to_str_buf((char[40]){0}, 40, (guid))
char *mp_HRESULT_to_str_buf(char *buf, size_t buf_size, HRESULT hr);