diff --git a/modules/juce_browser_plugin/wrapper/juce_ActiveX_GlueCode.cpp b/modules/juce_browser_plugin/wrapper/juce_ActiveX_GlueCode.cpp index 67d3bcf206..22612ed175 100644 --- a/modules/juce_browser_plugin/wrapper/juce_ActiveX_GlueCode.cpp +++ b/modules/juce_browser_plugin/wrapper/juce_ActiveX_GlueCode.cpp @@ -175,8 +175,8 @@ public: HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) { - if (id == IID_IUnknown) { AddRef(); *result = (IUnknown*) this; return S_OK; } - else if (id == IID_IDispatch) { AddRef(); *result = (IDispatch*) this; return S_OK; } + if (id == IID_IUnknown) { AddRef(); *result = (IUnknown*) this; return S_OK; } + if (id == IID_IDispatch) { AddRef(); *result = (IDispatch*) this; return S_OK; } *result = 0; return E_NOINTERFACE; @@ -595,12 +595,12 @@ public: HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) { - if (id == IID_IUnknown) { AddRef(); *result = (IUnknown*) this; return S_OK; } - else if (id == IID_IDispatch) { AddRef(); *result = (IDispatch*) this; return S_OK; } - else if (id == IID_IObjectWithSite) { AddRef(); *result = (IObjectWithSite*) this; return S_OK; } - else if (id == IID_IObjectSafety) { AddRef(); *result = (IObjectSafety*) this; return S_OK; } - else if (id == IID_IOleInPlaceObject) { AddRef(); *result = (IOleInPlaceObject*) this; return S_OK; } - else if (id == IID_IOleWindow) { AddRef(); *result = (IOleWindow*) (IOleInPlaceObject*) this; return S_OK; } + if (id == IID_IUnknown) { AddRef(); *result = (IUnknown*) this; return S_OK; } + if (id == IID_IDispatch) { AddRef(); *result = (IDispatch*) this; return S_OK; } + if (id == IID_IObjectWithSite) { AddRef(); *result = (IObjectWithSite*) this; return S_OK; } + if (id == IID_IObjectSafety) { AddRef(); *result = (IObjectSafety*) this; return S_OK; } + if (id == IID_IOleInPlaceObject) { AddRef(); *result = (IOleInPlaceObject*) this; return S_OK; } + if (id == IID_IOleWindow) { AddRef(); *result = (IOleWindow*) (IOleInPlaceObject*) this; return S_OK; } *result = 0; return E_NOINTERFACE; @@ -754,8 +754,8 @@ public: HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) { - if (id == IID_IUnknown) { AddRef(); *result = (IUnknown*) this; return S_OK; } - else if (id == IID_IClassFactory) { AddRef(); *result = (IClassFactory*) this; return S_OK; } + if (id == IID_IUnknown) { AddRef(); *result = (IUnknown*) this; return S_OK; } + if (id == IID_IClassFactory) { AddRef(); *result = (IClassFactory*) this; return S_OK; } *result = nullptr; return E_NOINTERFACE; diff --git a/modules/juce_core/native/juce_win32_ComSmartPtr.h b/modules/juce_core/native/juce_win32_ComSmartPtr.h index 2cf3b725af..e8d940d03f 100644 --- a/modules/juce_core/native/juce_win32_ComSmartPtr.h +++ b/modules/juce_core/native/juce_win32_ComSmartPtr.h @@ -105,6 +105,21 @@ public: protected: ULONG refCount; + + JUCE_COMRESULT QueryInterface (REFIID refId, void** result) + { + if (refId == IID_IUnknown) + return castToType (result); + + *result = 0; + return E_NOINTERFACE; + } + + template + JUCE_COMRESULT castToType (void** result) + { + this->AddRef(); *result = dynamic_cast (this); return S_OK; + } }; /** Handy base class for writing COM objects, providing ref-counting and a basic QueryInterface method. @@ -118,11 +133,10 @@ public: JUCE_COMRESULT QueryInterface (REFIID refId, void** result) { - if (refId == __uuidof (ComClass)) { this->AddRef(); *result = dynamic_cast (this); return S_OK; } - if (refId == IID_IUnknown) { this->AddRef(); *result = dynamic_cast (this); return S_OK; } + if (refId == __uuidof (ComClass)) + return castToType (result); - *result = 0; - return E_NOINTERFACE; + return ComBaseClassHelperBase ::QueryInterface (refId, result); } }; diff --git a/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp b/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp index f7e9eb8a82..65e36a72c5 100644 --- a/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp +++ b/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp @@ -40,7 +40,8 @@ namespace DirectWriteTypeLayout JUCE_COMRESULT QueryInterface (REFIID refId, void** result) { - if (refId == __uuidof (IDWritePixelSnapping)) { AddRef(); *result = dynamic_cast (this); return S_OK; } + if (refId == __uuidof (IDWritePixelSnapping)) + return castToType (result); return ComBaseClassHelper::QueryInterface (refId, result); } diff --git a/modules/juce_video/native/juce_win32_CameraDevice.cpp b/modules/juce_video/native/juce_win32_CameraDevice.cpp index be6ec5c460..667ab33ec3 100644 --- a/modules/juce_video/native/juce_win32_CameraDevice.cpp +++ b/modules/juce_video/native/juce_win32_CameraDevice.cpp @@ -680,6 +680,14 @@ private: GrabberCallback (DShowCameraDeviceInteral& cam) : ComBaseClassHelperBase (0), owner (cam) {} + JUCE_COMRESULT QueryInterface (REFIID refId, void** result) + { + if (refId == IID_ISampleGrabberCB) + return castToType (result); + + return ComBaseClassHelperBase::QueryInterface (refId, result); + } + STDMETHODIMP SampleCB (double, IMediaSample*) { return E_FAIL; } STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)