1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Fixed some COM object ref-counting.

This commit is contained in:
jules 2012-12-18 18:05:36 +00:00
parent 80dc4c57b0
commit e58b915300
6 changed files with 21 additions and 24 deletions

View file

@ -29,10 +29,9 @@ namespace WindowsMediaCodec
class JuceIStream : public ComBaseClassHelper <IStream>
{
public:
JuceIStream (InputStream& source_) noexcept
: source (source_)
JuceIStream (InputStream& in) noexcept
: ComBaseClassHelper <IStream> (0), source (in)
{
resetReferenceCount();
}
JUCE_COMRESULT Commit (DWORD) { return S_OK; }

View file

@ -97,14 +97,12 @@ template <class ComClass>
class ComBaseClassHelperBase : public ComClass
{
public:
ComBaseClassHelperBase() : refCount (1) {}
ComBaseClassHelperBase (unsigned int initialRefCount) : refCount (initialRefCount) {}
virtual ~ComBaseClassHelperBase() {}
ULONG __stdcall AddRef() { return ++refCount; }
ULONG __stdcall Release() { const ULONG r = --refCount; if (r == 0) delete this; return r; }
void resetReferenceCount() noexcept { refCount = 0; }
protected:
ULONG refCount;
};
@ -115,7 +113,7 @@ template <class ComClass>
class ComBaseClassHelper : public ComBaseClassHelperBase <ComClass>
{
public:
ComBaseClassHelper() {}
ComBaseClassHelper (unsigned int initialRefCount = 1) : ComBaseClassHelperBase <ComClass> (initialRefCount) {}
~ComBaseClassHelper() {}
JUCE_COMRESULT QueryInterface (REFIID refId, void** result)

View file

@ -115,7 +115,7 @@ namespace ColourHelpers
if (h < 3.0f) return PixelARGB (alpha, x, intV, (uint8) roundToInt (v * (1.0f - (s * (1.0f - f)))));
if (h < 4.0f) return PixelARGB (alpha, x, (uint8) roundToInt (v * (1.0f - s * f)), intV);
if (h < 5.0f) return PixelARGB (alpha, (uint8) roundToInt (v * (1.0f - (s * (1.0f - f)))), x, intV);
else return PixelARGB (alpha, intV, x, (uint8) roundToInt (v * (1.0f - s * f)));
return PixelARGB (alpha, intV, x, (uint8) roundToInt (v * (1.0f - s * f)));
}
float hue, saturation, brightness;

View file

@ -27,15 +27,15 @@
#if JUCE_USE_DIRECTWRITE
namespace DirectWriteTypeLayout
{
class CustomDirectWriteTextRenderer : public ComBaseClassHelper <IDWriteTextRenderer>
class CustomDirectWriteTextRenderer : public ComBaseClassHelper<IDWriteTextRenderer>
{
public:
CustomDirectWriteTextRenderer (IDWriteFontCollection* const fontCollection_)
: fontCollection (fontCollection_),
CustomDirectWriteTextRenderer (IDWriteFontCollection* const fonts)
: ComBaseClassHelper<IDWriteTextRenderer> (0),
fontCollection (fonts),
currentLine (-1),
lastOriginY (-10000.0f)
{
resetReferenceCount();
}
JUCE_COMRESULT QueryInterface (REFIID refId, void** result)

View file

@ -54,7 +54,7 @@ namespace ActiveXHelpers
class JuceOleInPlaceFrame : public ComBaseClassHelper <IOleInPlaceFrame>
{
public:
JuceOleInPlaceFrame (HWND window_) : window (window_) {}
JuceOleInPlaceFrame (HWND hwnd) : window (hwnd) {}
JUCE_COMRESULT GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
JUCE_COMRESULT ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
@ -77,8 +77,8 @@ namespace ActiveXHelpers
class JuceIOleInPlaceSite : public ComBaseClassHelper <IOleInPlaceSite>
{
public:
JuceIOleInPlaceSite (HWND window_)
: window (window_),
JuceIOleInPlaceSite (HWND hwnd)
: window (hwnd),
frame (new JuceOleInPlaceFrame (window))
{}
@ -161,11 +161,9 @@ namespace ActiveXHelpers
HWND getHWND (const ActiveXControlComponent* const component)
{
HWND hwnd = 0;
const IID iid = IID_IOleWindow;
IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
if (window != nullptr)
if (IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid))
{
window->GetWindow (&hwnd);
window->Release();
@ -338,12 +336,8 @@ void ActiveXControlComponent::paint (Graphics& g)
bool ActiveXControlComponent::createControl (const void* controlIID)
{
deleteControl();
ComponentPeer* const peer = getPeer();
// the component must have already been added to a real window when you call this!
jassert (peer != nullptr);
if (peer != nullptr)
if (ComponentPeer* const peer = getPeer())
{
const Rectangle<int> bounds (getTopLevelComponent()->getLocalArea (this, getLocalBounds()));
HWND hwnd = (HWND) peer->getNativeHandle();
@ -383,6 +377,11 @@ bool ActiveXControlComponent::createControl (const void* controlIID)
}
}
}
else
{
// the component must have already been added to a real window when you call this!
jassertfalse;
}
return false;
}

View file

@ -677,7 +677,8 @@ private:
class GrabberCallback : public ComBaseClassHelperBase <ISampleGrabberCB>
{
public:
GrabberCallback (DShowCameraDeviceInteral& cam) : owner (cam) {}
GrabberCallback (DShowCameraDeviceInteral& cam)
: ComBaseClassHelperBase <ISampleGrabberCB> (0), owner (cam) {}
STDMETHODIMP SampleCB (double, IMediaSample*) { return E_FAIL; }