From 9692814502223574b575931d32ddd458b9476bb6 Mon Sep 17 00:00:00 2001 From: James Ross-Gowan Date: Sun, 29 Jan 2017 23:59:24 +1100 Subject: 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. --- osdep/windows_utils.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'osdep') 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 +// 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); -- cgit v1.2.3