diff --git a/extras/juce demo/Source/MainDemoWindow.cpp b/extras/juce demo/Source/MainDemoWindow.cpp index ee2b51018f..b535ecb40e 100644 --- a/extras/juce demo/Source/MainDemoWindow.cpp +++ b/extras/juce demo/Source/MainDemoWindow.cpp @@ -32,47 +32,10 @@ class ContentComp : public Component, public MenuBarModel, public ApplicationCommandTarget { - //============================================================================== - MainDemoWindow* mainWindow; - - OldSchoolLookAndFeel oldLookAndFeel; - - Component* currentDemo; - int currentDemoId; - - TooltipWindow tooltipWindow; // to add tooltips to an application, you - // just need to create one of these and leave it - // there to do its work.. - - enum CommandIDs - { - showRendering = 0x2000, - showFontsAndText = 0x2001, - showWidgets = 0x2002, - showThreading = 0x2003, - showTreeView = 0x2004, - showAudio = 0x2005, - showDragAndDrop = 0x2006, - showOpenGL = 0x2007, - showQuicktime = 0x2008, - showInterprocessComms = 0x2009, - showTable = 0x2010, - showCamera = 0x2011, - showWebBrowser = 0x2012, - showCodeEditor = 0x2013, - - setDefaultLookAndFeel = 0x200b, - setOldSchoolLookAndFeel = 0x200c, - useNativeTitleBar = 0x200d, - useNativeMenus = 0x200e, - goToKioskMode = 0x200f - }; - public: //============================================================================== ContentComp (MainDemoWindow* mainWindow_) : mainWindow (mainWindow_), - currentDemo (0), currentDemoId (0) { invokeDirectly (showRendering, true); @@ -83,8 +46,6 @@ public: // (need to do this because the old school look-and-feel object is one of our members, // so will be deleted with us, and would leave a dangling pointer if it's selected) LookAndFeel::setDefaultLookAndFeel (0); - - deleteAllChildren(); } //============================================================================== @@ -97,9 +58,7 @@ public: //============================================================================== void showDemo (Component* demoComp) { - delete currentDemo; currentDemo = demoComp; - addAndMakeVisible (currentDemo); resized(); } @@ -114,7 +73,7 @@ public: const PopupMenu getMenuForIndex (int menuIndex, const String& /*menuName*/) { - ApplicationCommandManager* const commandManager = mainWindow->commandManager; + ApplicationCommandManager* commandManager = &(mainWindow->commandManager); PopupMenu menu; @@ -492,6 +451,41 @@ public: } juce_UseDebuggingNewOperator + +private: + //============================================================================== + MainDemoWindow* mainWindow; + OldSchoolLookAndFeel oldLookAndFeel; + ScopedPointer currentDemo; + int currentDemoId; + + TooltipWindow tooltipWindow; // to add tooltips to an application, you + // just need to create one of these and leave it + // there to do its work.. + + enum CommandIDs + { + showRendering = 0x2000, + showFontsAndText = 0x2001, + showWidgets = 0x2002, + showThreading = 0x2003, + showTreeView = 0x2004, + showAudio = 0x2005, + showDragAndDrop = 0x2006, + showOpenGL = 0x2007, + showQuicktime = 0x2008, + showInterprocessComms = 0x2009, + showTable = 0x2010, + showCamera = 0x2011, + showWebBrowser = 0x2012, + showCodeEditor = 0x2013, + + setDefaultLookAndFeel = 0x200b, + setOldSchoolLookAndFeel = 0x200c, + useNativeTitleBar = 0x200d, + useNativeMenus = 0x200e, + goToKioskMode = 0x200f + }; }; //============================================================================== @@ -541,19 +535,17 @@ MainDemoWindow::MainDemoWindow() DocumentWindow::allButtons, true) { - commandManager = new ApplicationCommandManager(); - setResizable (true, false); // resizability is a property of ResizableWindow setResizeLimits (400, 300, 8192, 8192); ContentComp* contentComp = new ContentComp (this); - commandManager->registerAllCommandsForTarget (contentComp); - commandManager->registerAllCommandsForTarget (JUCEApplication::getInstance()); + commandManager.registerAllCommandsForTarget (contentComp); + commandManager.registerAllCommandsForTarget (JUCEApplication::getInstance()); // this lets the command manager use keypresses that arrive in our window to send // out commands - addKeyListener (commandManager->getKeyMappings()); + addKeyListener (commandManager.getKeyMappings()); // sets the main content component for the window to be this tabbed // panel. This will be deleted when the window is deleted. @@ -565,28 +557,24 @@ MainDemoWindow::MainDemoWindow() // tells our menu bar model that it should watch this command manager for // changes, and send change messages accordingly. - contentComp->setApplicationCommandManagerToWatch (commandManager); + contentComp->setApplicationCommandManagerToWatch (&commandManager); setVisible (true); -#if JUCE_WINDOWS || JUCE_LINUX + #if JUCE_WINDOWS || JUCE_LINUX taskbarIcon = new DemoTaskbarComponent(); -#endif + #endif } MainDemoWindow::~MainDemoWindow() { -#if JUCE_WINDOWS || JUCE_LINUX - deleteAndZero (taskbarIcon); -#endif - // because we've set the content comp to be used as our menu bar model, we // have to switch this off before deleting the content comp.. setMenuBar (0); -#if JUCE_MAC // ..and also the main bar if we're using that on a Mac... + #if JUCE_MAC // ..and also the main bar if we're using that on a Mac... MenuBarModel::setMacMainMenu (0); -#endif + #endif // setting our content component to 0 will delete the current one, and // that will in turn delete all its child components. You don't always @@ -595,8 +583,6 @@ MainDemoWindow::~MainDemoWindow() // make sure our content comp has gone away before deleting our command // manager. setContentComponent (0, true); - - delete commandManager; } void MainDemoWindow::closeButtonPressed() diff --git a/extras/juce demo/Source/MainDemoWindow.h b/extras/juce demo/Source/MainDemoWindow.h index f3146341e5..731ba74cfe 100644 --- a/extras/juce demo/Source/MainDemoWindow.h +++ b/extras/juce demo/Source/MainDemoWindow.h @@ -40,10 +40,10 @@ public: void closeButtonPressed(); // the command manager object used to dispatch command events - ApplicationCommandManager* commandManager; + ApplicationCommandManager commandManager; private: - Component* taskbarIcon; + ScopedPointer taskbarIcon; }; diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index e5865f9f33..3cce2035c5 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -641,35 +641,54 @@ public: ComSmartPtr() throw() : p (0) {} ComSmartPtr (ComClass* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); } ComSmartPtr (const ComSmartPtr& p_) : p (p_.p) { if (p != 0) p->AddRef(); } - ~ComSmartPtr() { if (p != 0) p->Release(); } + ~ComSmartPtr() { release(); } operator ComClass*() const throw() { return p; } ComClass& operator*() const throw() { return *p; } - ComClass** operator&() throw() { return &p; } ComClass* operator->() const throw() { return p; } - ComClass* operator= (ComClass* const newP) + ComSmartPtr& operator= (ComClass* const newP) { if (newP != 0) newP->AddRef(); - if (p != 0) p->Release(); + release(); p = newP; - return newP; + return *this; } - ComClass* operator= (const ComSmartPtr& newP) { return operator= (newP.p); } + ComSmartPtr& operator= (const ComSmartPtr& newP) { return operator= (newP.p); } - HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext = CLSCTX_INPROC_SERVER) + // Releases and nullifies this pointer and returns its address + ComClass** resetAndGetPointerAddress() { -#ifndef __MINGW32__ - operator= (0); - return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof (ComClass), (void**) &p); -#else - return S_FALSE; -#endif + release(); + p = 0; + return &p; + } + + HRESULT CoCreateInstance (REFCLSID classUUID, DWORD dwClsContext = CLSCTX_INPROC_SERVER) + { + #ifndef __MINGW32__ + return ::CoCreateInstance (classUUID, 0, dwClsContext, __uuidof (ComClass), (void**) resetAndGetPointerAddress()); + #else + return E_NOTIMPL; + #endif + } + + template + HRESULT QueryInterface (REFCLSID classUUID, ComSmartPtr& destObject) const + { + if (p == 0) + return E_POINTER; + + return p->QueryInterface (classUUID, (void**) destObject.resetAndGetPointerAddress()); } private: ComClass* p; + + void release() { if (p != 0) p->Release(); } + + ComClass** operator&() throw(); // private to avoid it being used accidentally }; /** Handy base class for writing COM objects, providing ref-counting and a basic QueryInterface method. @@ -22777,7 +22796,7 @@ public: } } - int framesToDo = jmin (numSamples, bufferList->mBuffers[0].mDataByteSize / inputStreamDesc.mBytesPerFrame); + int framesToDo = jmin (numSamples, (int) (bufferList->mBuffers[0].mDataByteSize / inputStreamDesc.mBytesPerFrame)); bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * framesToDo; UInt32 outFlags = 0; @@ -37418,26 +37437,24 @@ class ProcessorParameterPropertyComp : public PropertyComponent, public AsyncUpdater { public: - ProcessorParameterPropertyComp (const String& name, - AudioProcessor* const owner_, - const int index_) + ProcessorParameterPropertyComp (const String& name, AudioProcessor& owner_, int index_) : PropertyComponent (name), owner (owner_), - index (index_) + index (index_), + slider (owner_, index_) { - addAndMakeVisible (slider = new ParamSlider (owner_, index_)); - owner_->addListener (this); + addAndMakeVisible (&slider); + owner_.addListener (this); } ~ProcessorParameterPropertyComp() { - owner->removeListener (this); - deleteAllChildren(); + owner.removeListener (this); } void refresh() { - slider->setValue (owner->getParameter (index), false); + slider.setValue (owner.getParameter (index), false); } void audioProcessorChanged (AudioProcessor*) {} @@ -37456,14 +37473,11 @@ public: juce_UseDebuggingNewOperator private: - AudioProcessor* const owner; - const int index; - Slider* slider; class ParamSlider : public Slider { public: - ParamSlider (AudioProcessor* const owner_, const int index_) + ParamSlider (AudioProcessor& owner_, const int index_) : Slider (String::empty), owner (owner_), index (index_) @@ -37482,25 +37496,29 @@ private: { const float newVal = (float) getValue(); - if (owner->getParameter (index) != newVal) - owner->setParameter (index, newVal); + if (owner.getParameter (index) != newVal) + owner.setParameter (index, newVal); } const String getTextFromValue (double /*value*/) { - return owner->getParameterText (index); + return owner.getParameterText (index); } juce_UseDebuggingNewOperator private: - AudioProcessor* const owner; + AudioProcessor& owner; const int index; ParamSlider (const ParamSlider&); ParamSlider& operator= (const ParamSlider&); }; + AudioProcessor& owner; + const int index; + ParamSlider slider; + ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&); ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&); }; @@ -37508,6 +37526,7 @@ private: GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_) : AudioProcessorEditor (owner_) { + jassert (owner_ != 0); setOpaque (true); addAndMakeVisible (panel = new PropertyPanel()); @@ -37523,7 +37542,7 @@ GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const if (name.trim().isEmpty()) name = "Unnamed"; - ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i); + ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, *owner_, i); params.add (pc); totalHeight += pc->getPreferredHeight(); } @@ -61456,12 +61475,6 @@ public: { } - Component::SafePointer component; - Rectangle destination; - int msElapsed, msTotal; - double startSpeed, midSpeed, endSpeed, lastProgress; - double left, top, right, bottom; - bool useTimeslice (const int elapsed) { if (component == 0) @@ -61507,6 +61520,12 @@ public: component->setBounds (destination); } + Component::SafePointer component; + Rectangle destination; + int msElapsed, msTotal; + double startSpeed, midSpeed, endSpeed, lastProgress; + double left, top, right, bottom; + private: inline double timeToDistance (const double time) const { @@ -61523,8 +61542,6 @@ ComponentAnimator::ComponentAnimator() ComponentAnimator::~ComponentAnimator() { - cancelAllAnimations (false); - jassert (tasks.size() == 0); } ComponentAnimator::AnimationTask* ComponentAnimator::findTaskFor (Component* const component) const @@ -61581,15 +61598,13 @@ void ComponentAnimator::animateComponent (Component* const component, void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions) { - for (int i = tasks.size(); --i >= 0;) + if (tasks.size() > 0) { - AnimationTask* const at = tasks.getUnchecked(i); - if (moveComponentsToTheirFinalPositions) - at->moveToFinalDestination(); + for (int i = tasks.size(); --i >= 0;) + tasks.getUnchecked(i)->moveToFinalDestination(); - delete at; - tasks.remove (i); + tasks.clear(); sendChangeMessage (this); } } @@ -61604,8 +61619,7 @@ void ComponentAnimator::cancelAnimation (Component* const component, if (moveComponentToItsFinalPosition) at->moveToFinalDestination(); - tasks.removeValue (at); - delete at; + tasks.removeObject (at); sendChangeMessage (this); } } @@ -61638,12 +61652,9 @@ void ComponentAnimator::timerCallback() for (int i = tasks.size(); --i >= 0;) { - AnimationTask* const at = tasks.getUnchecked(i); - - if (! at->useTimeslice (elapsed)) + if (! tasks.getUnchecked(i)->useTimeslice (elapsed)) { tasks.remove (i); - delete at; sendChangeMessage (this); } } @@ -237479,7 +237490,8 @@ bool PNGImageFormat::writeImageToStream (const Image& image, OutputStream& out) } } - png_write_rows (pngWriteStruct, &rowData, 1); + png_bytep rowPtr = rowData; + png_write_rows (pngWriteStruct, &rowPtr, 1); } png_write_end (pngWriteStruct, pngInfoStruct); @@ -237553,10 +237565,7 @@ public: const MidiMessage m (d, numBytes, used, 0, time); if (used <= 0) - { - jassertfalse; // malformed midi message - break; - } + break; // malformed message.. callback.handleIncomingMidiMessage (input, m); numBytes -= used; @@ -238907,7 +238916,7 @@ const File File::getLinkedTarget() const if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink))) { ComSmartPtr persistFile; - if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile))) + if (SUCCEEDED (shellLink.QueryInterface (IID_IPersistFile, persistFile))) { if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ)) && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI))) @@ -244662,8 +244671,11 @@ namespace ActiveXHelpers HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo) { - *lplpFrame = frame; - *lplpDoc = 0; + /* Note: if you call AddRef on the frame here, then some types of object (e.g. web browser control) cause leaks.. + If you don't call AddRef then others crash (e.g. QuickTime).. Bit of a catch-22, so letting it leak is probably preferable. + */ + if (lplpFrame != 0) { frame->AddRef(); *lplpFrame = frame; } + if (lplpDoc != 0) *lplpDoc = 0; lpFrameInfo->fMDIApp = FALSE; lpFrameInfo->hwndFrame = window; lpFrameInfo->haccel = 0; @@ -244767,7 +244779,7 @@ namespace ActiveXHelpers class ActiveXControlComponent::Pimpl : public ComponentMovementWatcher { - ActiveXControlComponent* const owner; + ActiveXControlComponent& owner; bool wasShowing; public: @@ -244776,10 +244788,10 @@ public: IOleClientSite* clientSite; IOleObject* control; - Pimpl (HWND hwnd, ActiveXControlComponent* const owner_) - : ComponentMovementWatcher (owner_), + Pimpl (HWND hwnd, ActiveXControlComponent& owner_) + : ComponentMovementWatcher (&owner_), owner (owner_), - wasShowing (owner_ != 0 && owner_->isShowing()), + wasShowing (owner_.isShowing()), controlHWND (0), storage (new ActiveXHelpers::JuceIStorage()), clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)), @@ -244801,24 +244813,24 @@ public: void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) { - Component* const topComp = owner->getTopLevelComponent(); + Component* const topComp = owner.getTopLevelComponent(); if (topComp->getPeer() != 0) { - const Point pos (owner->relativePositionToOtherComponent (topComp, Point())); + const Point pos (owner.relativePositionToOtherComponent (topComp, Point())); - owner->setControlBounds (Rectangle (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight())); + owner.setControlBounds (Rectangle (pos.getX(), pos.getY(), owner.getWidth(), owner.getHeight())); } } void componentPeerChanged() { - const bool isShowingNow = owner->isShowing(); + const bool isShowingNow = owner.isShowing(); if (wasShowing != isShowingNow) { wasShowing = isShowingNow; - owner->setControlVisible (isShowingNow); + owner.setControlVisible (isShowingNow); } componentMovedOrResized (true, true); @@ -244908,7 +244920,7 @@ bool ActiveXControlComponent::createControl (const void* controlIID) const Point pos (relativePositionToOtherComponent (getTopLevelComponent(), Point())); HWND hwnd = (HWND) peer->getNativeHandle(); - ScopedPointer newControl (new Pimpl (hwnd, this)); + ScopedPointer newControl (new Pimpl (hwnd, *this)); HRESULT hr; if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0, @@ -248374,7 +248386,7 @@ public: int getIntProperty (const LPOLESTR name, const int defaultReturn) const { ComSmartPtr prop; - if (FAILED (discRecorder->GetRecorderProperties (&prop))) + if (FAILED (discRecorder->GetRecorderProperties (prop.resetAndGetPointerAddress()))) return defaultReturn; PROPSPEC iPropSpec; @@ -248389,7 +248401,7 @@ public: bool setIntProperty (const LPOLESTR name, const int value) const { ComSmartPtr prop; - if (FAILED (discRecorder->GetRecorderProperties (&prop))) + if (FAILED (discRecorder->GetRecorderProperties (prop.resetAndGetPointerAddress()))) return false; PROPSPEC iPropSpec; @@ -252658,11 +252670,11 @@ static const String getDeviceID (IMMDevice* const device) return s; } -static EDataFlow getDataFlow (IMMDevice* const device) +static EDataFlow getDataFlow (const ComSmartPtr& device) { EDataFlow flow = eRender; ComSmartPtr endPoint; - if (check (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint))) + if (check (device.QueryInterface (__uuidof (IMMEndpoint), endPoint))) (void) check (endPoint->GetDataFlow (&flow)); return flow; @@ -253667,7 +253679,7 @@ public: if (FAILED (hr)) return; - hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl); + hr = graphBuilder.QueryInterface (IID_IMediaControl, mediaControl); if (FAILED (hr)) return; @@ -253675,7 +253687,7 @@ public: ComSmartPtr streamConfig; hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter, - IID_IAMStreamConfig, (void**) &streamConfig); + IID_IAMStreamConfig, (void**) streamConfig.resetAndGetPointerAddress()); if (streamConfig != 0) { @@ -253706,7 +253718,7 @@ public: if (FAILED (hr)) return; - hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber); + hr = sampleGrabberBase.QueryInterface (IID_ISampleGrabber, sampleGrabber); if (FAILED (hr)) return; @@ -253718,16 +253730,16 @@ public: sampleGrabber->SetMediaType (&mt); callback = new GrabberCallback (*this); - sampleGrabber->SetCallback (callback, 1); + hr = sampleGrabber->SetCallback (callback, 1); hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber")); if (FAILED (hr)) return; ComSmartPtr grabberInputPin; - if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture") - && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview") - && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin))) + if (! (getPin (smartTee, PINDIR_OUTPUT, smartTeeCaptureOutputPin, "capture") + && getPin (smartTee, PINDIR_OUTPUT, smartTeePreviewOutputPin, "preview") + && getPin (sampleGrabberBase, PINDIR_INPUT, grabberInputPin))) return; hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin); @@ -253798,10 +253810,10 @@ public: recordNextFrameTime = false; ComSmartPtr pin; - if (getPin (filter, PINDIR_OUTPUT, &pin)) + if (getPin (filter, PINDIR_OUTPUT, pin)) { ComSmartPtr pushSource; - HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource); + HRESULT hr = pin.QueryInterface (IID_IAMPushSource, pushSource); if (pushSource != 0) { @@ -253871,7 +253883,7 @@ public: if (SUCCEEDED (hr)) { ComSmartPtr fileSink; - hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink); + hr = asfWriter.QueryInterface (IID_IFileSinkFilter, fileSink); if (SUCCEEDED (hr)) { @@ -253884,10 +253896,10 @@ public: if (SUCCEEDED (hr)) { ComSmartPtr asfConfig; - hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig); + hr = asfWriter.QueryInterface (IID_IConfigAsfWriter, asfConfig); asfConfig->SetIndexMode (true); ComSmartPtr profileManager; - hr = WMCreateProfileManager (&profileManager); + hr = WMCreateProfileManager (profileManager.resetAndGetPointerAddress()); // This gibberish is the DirectShow profile for a video-only wmv file. String prof (" currentProfile; - hr = profileManager->LoadProfileByData ((const WCHAR*) prof, ¤tProfile); + hr = profileManager->LoadProfileByData ((const WCHAR*) prof, currentProfile.resetAndGetPointerAddress()); hr = asfConfig->ConfigureFilterUsingProfile (currentProfile); if (SUCCEEDED (hr)) { ComSmartPtr asfWriterInputPin; - if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01")) + if (getPin (asfWriter, PINDIR_INPUT, asfWriterInputPin, "Video Input 01")) { hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin); @@ -253992,7 +254004,7 @@ public: owner->addChangeListener (this); owner->addUser(); owner->viewerComps.add (this); - setSize (owner_->width, owner_->height); + setSize (owner->width, owner->height); } ~DShowCaptureViewerComp() @@ -254152,14 +254164,14 @@ private: return false; } - static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0) + static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, ComSmartPtr& result, const char* pinName = 0) { ComSmartPtr enumerator; ComSmartPtr pin; - filter->EnumPins (&enumerator); + filter->EnumPins (enumerator.resetAndGetPointerAddress()); - while (enumerator->Next (1, &pin, 0) == S_OK) + while (enumerator->Next (1, pin.resetAndGetPointerAddress(), 0) == S_OK) { PIN_DIRECTION dir; pin->QueryDirection (&dir); @@ -254172,8 +254184,7 @@ private: if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName))) { - pin->AddRef(); - *result = pin; + result = pin; return true; } } @@ -254186,20 +254197,20 @@ private: { ComSmartPtr in, out; - return getPin (first, PINDIR_OUTPUT, &out) - && getPin (second, PINDIR_INPUT, &in) + return getPin (first, PINDIR_OUTPUT, out) + && getPin (second, PINDIR_INPUT, in) && SUCCEEDED (graphBuilder->Connect (out, in)); } bool addGraphToRot() { ComSmartPtr rot; - if (FAILED (GetRunningObjectTable (0, &rot))) + if (FAILED (GetRunningObjectTable (0, rot.resetAndGetPointerAddress()))) return false; ComSmartPtr moniker; WCHAR buffer[128]; - HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker); + HRESULT hr = CreateItemMoniker (_T("!"), buffer, moniker.resetAndGetPointerAddress()); if (FAILED (hr)) return false; @@ -254211,7 +254222,7 @@ private: { ComSmartPtr rot; - if (SUCCEEDED (GetRunningObjectTable (0, &rot))) + if (SUCCEEDED (GetRunningObjectTable (0, rot.resetAndGetPointerAddress()))) rot->Revoke (graphRegistrationID); } @@ -254338,22 +254349,22 @@ static ComSmartPtr enumerateCameras (StringArray* const names, if (SUCCEEDED (hr)) { ComSmartPtr enumerator; - hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0); + hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, enumerator.resetAndGetPointerAddress(), 0); if (SUCCEEDED (hr) && enumerator != 0) { - ComSmartPtr captureFilter; ComSmartPtr moniker; ULONG fetched; - while (enumerator->Next (1, &moniker, &fetched) == S_OK) + while (enumerator->Next (1, moniker.resetAndGetPointerAddress(), &fetched) == S_OK) { - hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter); + ComSmartPtr captureFilter; + hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) captureFilter.resetAndGetPointerAddress()); if (SUCCEEDED (hr)) { ComSmartPtr propertyBag; - hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag); + hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) propertyBag.resetAndGetPointerAddress()); if (SUCCEEDED (hr)) { @@ -254372,17 +254383,12 @@ static ComSmartPtr enumerateCameras (StringArray* const names, { name = var.bstrVal; result = captureFilter; - captureFilter = 0; break; } ++index; } - - moniker = 0; } - - captureFilter = 0; } } } @@ -254731,8 +254737,14 @@ bool File::isDirectory() const bool File::exists() const { + juce_statStruct info; + return fullPath.isNotEmpty() - && access (fullPath.toUTF8(), F_OK) == 0; + #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T + && (lstat64 (fullPath.toUTF8(), &info) == 0); + #else + && (lstat (fullPath.toUTF8(), &info) == 0); + #endif } bool File::existsAsFile() const @@ -255302,16 +255314,16 @@ bool File::isHidden() const return getFileName().startsWithChar ('.'); } -static const File juce_readlink (const char* const utf8, const File& defaultFile) +static const File juce_readlink (const String& file, const File& defaultFile) { const int size = 8192; HeapBlock buffer; buffer.malloc (size + 4); - const size_t numBytes = readlink (utf8, buffer, size); + const size_t numBytes = readlink (file.toUTF8(), buffer, size); if (numBytes > 0 && numBytes <= size) - return File (String::fromUTF8 (buffer, (int) numBytes)); + return File (file).getSiblingFile (String::fromUTF8 (buffer, (int) numBytes)); return defaultFile; } @@ -264568,8 +264580,14 @@ bool File::isDirectory() const bool File::exists() const { + juce_statStruct info; + return fullPath.isNotEmpty() - && access (fullPath.toUTF8(), F_OK) == 0; + #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T + && (lstat64 (fullPath.toUTF8(), &info) == 0); + #else + && (lstat (fullPath.toUTF8(), &info) == 0); + #endif } bool File::existsAsFile() const diff --git a/juce_amalgamated.h b/juce_amalgamated.h index b9fb1527c6..e798ee533d 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -64,7 +64,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 52 -#define JUCE_BUILDNUMBER 74 +#define JUCE_BUILDNUMBER 75 /** Current Juce version number. @@ -2951,7 +2951,7 @@ private: long juce_InterlockedExchangeAdd (volatile long* a, long b) throw(); long juce_InterlockedCompareExchange (volatile long* a, long b, long c) throw(); __int64 juce_InterlockedCompareExchange64 (volatile __int64* a, __int64 b, __int64 c) throw(); - void juce_MemoryBarrier() throw() { long x = 0; juce_InterlockedIncrement (&x); } + inline void juce_MemoryBarrier() throw() { long x = 0; juce_InterlockedIncrement (&x); } #endif #if JUCE_64BIT @@ -3430,18 +3430,6 @@ public: template inline ElementType* operator+ (IndexType index) const throw() { return data + index; } - /** Returns a reference to the raw data pointer. - Beware that the pointer returned here will become invalid as soon as you call - any of the allocator methods on this object! - */ - inline ElementType* const* operator&() const throw() { return static_cast (&data); } - - /** Returns a reference to the raw data pointer. - Beware that the pointer returned here will become invalid as soon as you call - any of the allocator methods on this object! - */ - inline ElementType** operator&() throw() { return static_cast (&data); } - /** Compares the pointer with another pointer. This can be handy for checking whether this is a null pointer. */ @@ -6720,9 +6708,6 @@ public: /** Lets you access methods and properties of the object that this ScopedPointer refers to. */ inline ObjectType* operator->() const throw() { return object; } - /** Returns a reference to the address of the object that this ScopedPointer refers to. */ - inline ObjectType* const* operator&() const throw() { return static_cast (&object); } - /** Removes the current object from this ScopedPointer without deleting it. This will return the current object, and set the ScopedPointer to a null pointer. @@ -28475,11 +28460,8 @@ public: e.g. @code class MyJUCEApp : public JUCEApplication { - MyApplicationWindow* myMainWindow; - public: MyJUCEApp() - : myMainWindow (0) { } @@ -28496,7 +28478,7 @@ public: void shutdown() { - delete myMainWindow; + myMainWindow = 0; } const String getApplicationName() @@ -28508,6 +28490,9 @@ public: { return "1.0"; } + + private: + ScopedPointer myMainWindow; }; // this creates wrapper code to actually launch the app properly. @@ -45606,7 +45591,7 @@ public: private: class AnimationTask; - Array tasks; + OwnedArray tasks; uint32 lastTime; AnimationTask* findTaskFor (Component* component) const; diff --git a/src/application/juce_Application.h b/src/application/juce_Application.h index 8c2145b094..4459faf3bf 100644 --- a/src/application/juce_Application.h +++ b/src/application/juce_Application.h @@ -46,11 +46,8 @@ e.g. @code class MyJUCEApp : public JUCEApplication { - MyApplicationWindow* myMainWindow; - public: MyJUCEApp() - : myMainWindow (0) { } @@ -67,7 +64,7 @@ void shutdown() { - delete myMainWindow; + myMainWindow = 0; } const String getApplicationName() @@ -79,6 +76,9 @@ { return "1.0"; } + + private: + ScopedPointer myMainWindow; }; // this creates wrapper code to actually launch the app properly. diff --git a/src/audio/audio_file_formats/juce_QuickTimeAudioFormat.cpp b/src/audio/audio_file_formats/juce_QuickTimeAudioFormat.cpp index 6247c7826d..e2502243a5 100644 --- a/src/audio/audio_file_formats/juce_QuickTimeAudioFormat.cpp +++ b/src/audio/audio_file_formats/juce_QuickTimeAudioFormat.cpp @@ -256,7 +256,7 @@ public: } } - int framesToDo = jmin (numSamples, bufferList->mBuffers[0].mDataByteSize / inputStreamDesc.mBytesPerFrame); + int framesToDo = jmin (numSamples, (int) (bufferList->mBuffers[0].mDataByteSize / inputStreamDesc.mBytesPerFrame)); bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * framesToDo; UInt32 outFlags = 0; diff --git a/src/audio/processors/juce_GenericAudioProcessorEditor.cpp b/src/audio/processors/juce_GenericAudioProcessorEditor.cpp index 61d15783e2..1e5926c1e4 100644 --- a/src/audio/processors/juce_GenericAudioProcessorEditor.cpp +++ b/src/audio/processors/juce_GenericAudioProcessorEditor.cpp @@ -38,26 +38,24 @@ class ProcessorParameterPropertyComp : public PropertyComponent, public AsyncUpdater { public: - ProcessorParameterPropertyComp (const String& name, - AudioProcessor* const owner_, - const int index_) + ProcessorParameterPropertyComp (const String& name, AudioProcessor& owner_, int index_) : PropertyComponent (name), owner (owner_), - index (index_) + index (index_), + slider (owner_, index_) { - addAndMakeVisible (slider = new ParamSlider (owner_, index_)); - owner_->addListener (this); + addAndMakeVisible (&slider); + owner_.addListener (this); } ~ProcessorParameterPropertyComp() { - owner->removeListener (this); - deleteAllChildren(); + owner.removeListener (this); } void refresh() { - slider->setValue (owner->getParameter (index), false); + slider.setValue (owner.getParameter (index), false); } void audioProcessorChanged (AudioProcessor*) {} @@ -77,15 +75,11 @@ public: juce_UseDebuggingNewOperator private: - AudioProcessor* const owner; - const int index; - Slider* slider; - //============================================================================== class ParamSlider : public Slider { public: - ParamSlider (AudioProcessor* const owner_, const int index_) + ParamSlider (AudioProcessor& owner_, const int index_) : Slider (String::empty), owner (owner_), index (index_) @@ -104,26 +98,30 @@ private: { const float newVal = (float) getValue(); - if (owner->getParameter (index) != newVal) - owner->setParameter (index, newVal); + if (owner.getParameter (index) != newVal) + owner.setParameter (index, newVal); } const String getTextFromValue (double /*value*/) { - return owner->getParameterText (index); + return owner.getParameterText (index); } //============================================================================== juce_UseDebuggingNewOperator private: - AudioProcessor* const owner; + AudioProcessor& owner; const int index; ParamSlider (const ParamSlider&); ParamSlider& operator= (const ParamSlider&); }; + AudioProcessor& owner; + const int index; + ParamSlider slider; + ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&); ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&); }; @@ -133,6 +131,7 @@ private: GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_) : AudioProcessorEditor (owner_) { + jassert (owner_ != 0); setOpaque (true); addAndMakeVisible (panel = new PropertyPanel()); @@ -148,7 +147,7 @@ GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const if (name.trim().isEmpty()) name = "Unnamed"; - ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i); + ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, *owner_, i); params.add (pc); totalHeight += pc->getPreferredHeight(); } diff --git a/src/containers/juce_HeapBlock.h b/src/containers/juce_HeapBlock.h index 9716bd47ee..abf89f5a03 100644 --- a/src/containers/juce_HeapBlock.h +++ b/src/containers/juce_HeapBlock.h @@ -147,18 +147,6 @@ public: template inline ElementType* operator+ (IndexType index) const throw() { return data + index; } - /** Returns a reference to the raw data pointer. - Beware that the pointer returned here will become invalid as soon as you call - any of the allocator methods on this object! - */ - inline ElementType* const* operator&() const throw() { return static_cast (&data); } - - /** Returns a reference to the raw data pointer. - Beware that the pointer returned here will become invalid as soon as you call - any of the allocator methods on this object! - */ - inline ElementType** operator&() throw() { return static_cast (&data); } - //============================================================================== /** Compares the pointer with another pointer. This can be handy for checking whether this is a null pointer. diff --git a/src/containers/juce_ScopedPointer.h b/src/containers/juce_ScopedPointer.h index 8e3468e313..f439c29a53 100644 --- a/src/containers/juce_ScopedPointer.h +++ b/src/containers/juce_ScopedPointer.h @@ -139,9 +139,6 @@ public: /** Lets you access methods and properties of the object that this ScopedPointer refers to. */ inline ObjectType* operator->() const throw() { return object; } - /** Returns a reference to the address of the object that this ScopedPointer refers to. */ - inline ObjectType* const* operator&() const throw() { return static_cast (&object); } - //============================================================================== /** Removes the current object from this ScopedPointer without deleting it. diff --git a/src/core/juce_Atomic.h b/src/core/juce_Atomic.h index 5b5d4a18b3..46bb5a219b 100644 --- a/src/core/juce_Atomic.h +++ b/src/core/juce_Atomic.h @@ -207,7 +207,7 @@ private: long juce_InterlockedExchangeAdd (volatile long* a, long b) throw(); long juce_InterlockedCompareExchange (volatile long* a, long b, long c) throw(); __int64 juce_InterlockedCompareExchange64 (volatile __int64* a, __int64 b, __int64 c) throw(); - void juce_MemoryBarrier() throw() { long x = 0; juce_InterlockedIncrement (&x); } + inline void juce_MemoryBarrier() throw() { long x = 0; juce_InterlockedIncrement (&x); } #endif #if JUCE_64BIT diff --git a/src/core/juce_StandardHeader.h b/src/core/juce_StandardHeader.h index 3d0bc8cb93..4d08912f6c 100644 --- a/src/core/juce_StandardHeader.h +++ b/src/core/juce_StandardHeader.h @@ -33,7 +33,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 52 -#define JUCE_BUILDNUMBER 74 +#define JUCE_BUILDNUMBER 75 /** Current Juce version number. diff --git a/src/gui/components/layout/juce_ComponentAnimator.cpp b/src/gui/components/layout/juce_ComponentAnimator.cpp index fdf66f8da5..86352518c6 100644 --- a/src/gui/components/layout/juce_ComponentAnimator.cpp +++ b/src/gui/components/layout/juce_ComponentAnimator.cpp @@ -40,12 +40,6 @@ public: { } - Component::SafePointer component; - Rectangle destination; - int msElapsed, msTotal; - double startSpeed, midSpeed, endSpeed, lastProgress; - double left, top, right, bottom; - bool useTimeslice (const int elapsed) { if (component == 0) @@ -91,6 +85,12 @@ public: component->setBounds (destination); } + Component::SafePointer component; + Rectangle destination; + int msElapsed, msTotal; + double startSpeed, midSpeed, endSpeed, lastProgress; + double left, top, right, bottom; + private: inline double timeToDistance (const double time) const { @@ -108,8 +108,6 @@ ComponentAnimator::ComponentAnimator() ComponentAnimator::~ComponentAnimator() { - cancelAllAnimations (false); - jassert (tasks.size() == 0); } //============================================================================== @@ -167,15 +165,13 @@ void ComponentAnimator::animateComponent (Component* const component, void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions) { - for (int i = tasks.size(); --i >= 0;) + if (tasks.size() > 0) { - AnimationTask* const at = tasks.getUnchecked(i); - if (moveComponentsToTheirFinalPositions) - at->moveToFinalDestination(); + for (int i = tasks.size(); --i >= 0;) + tasks.getUnchecked(i)->moveToFinalDestination(); - delete at; - tasks.remove (i); + tasks.clear(); sendChangeMessage (this); } } @@ -190,8 +186,7 @@ void ComponentAnimator::cancelAnimation (Component* const component, if (moveComponentToItsFinalPosition) at->moveToFinalDestination(); - tasks.removeValue (at); - delete at; + tasks.removeObject (at); sendChangeMessage (this); } } @@ -224,12 +219,9 @@ void ComponentAnimator::timerCallback() for (int i = tasks.size(); --i >= 0;) { - AnimationTask* const at = tasks.getUnchecked(i); - - if (! at->useTimeslice (elapsed)) + if (! tasks.getUnchecked(i)->useTimeslice (elapsed)) { tasks.remove (i); - delete at; sendChangeMessage (this); } } diff --git a/src/gui/components/layout/juce_ComponentAnimator.h b/src/gui/components/layout/juce_ComponentAnimator.h index cd8bf20186..f4a2ab0ab5 100644 --- a/src/gui/components/layout/juce_ComponentAnimator.h +++ b/src/gui/components/layout/juce_ComponentAnimator.h @@ -128,7 +128,7 @@ public: private: class AnimationTask; - Array tasks; + OwnedArray tasks; uint32 lastTime; AnimationTask* findTaskFor (Component* component) const; diff --git a/src/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp b/src/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp index d35f308e50..f5d884da41 100644 --- a/src/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp +++ b/src/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp @@ -341,7 +341,8 @@ bool PNGImageFormat::writeImageToStream (const Image& image, OutputStream& out) } } - png_write_rows (pngWriteStruct, &rowData, 1); + png_bytep rowPtr = rowData; + png_write_rows (pngWriteStruct, &rowPtr, 1); } png_write_end (pngWriteStruct, pngInfoStruct); diff --git a/src/native/common/juce_MidiDataConcatenator.h b/src/native/common/juce_MidiDataConcatenator.h index 6905dd022a..47df5f6f54 100644 --- a/src/native/common/juce_MidiDataConcatenator.h +++ b/src/native/common/juce_MidiDataConcatenator.h @@ -65,10 +65,7 @@ public: const MidiMessage m (d, numBytes, used, 0, time); if (used <= 0) - { - jassertfalse; // malformed midi message - break; - } + break; // malformed message.. callback.handleIncomingMidiMessage (input, m); numBytes -= used; diff --git a/src/native/common/juce_posix_SharedCode.h b/src/native/common/juce_posix_SharedCode.h index d3d175aac2..6ee0e83860 100644 --- a/src/native/common/juce_posix_SharedCode.h +++ b/src/native/common/juce_posix_SharedCode.h @@ -246,8 +246,14 @@ bool File::isDirectory() const bool File::exists() const { + juce_statStruct info; + return fullPath.isNotEmpty() - && access (fullPath.toUTF8(), F_OK) == 0; + #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T + && (lstat64 (fullPath.toUTF8(), &info) == 0); + #else + && (lstat (fullPath.toUTF8(), &info) == 0); + #endif } bool File::existsAsFile() const diff --git a/src/native/linux/juce_linux_Files.cpp b/src/native/linux/juce_linux_Files.cpp index 11302cbfa0..0d9a3ff757 100644 --- a/src/native/linux/juce_linux_Files.cpp +++ b/src/native/linux/juce_linux_Files.cpp @@ -107,16 +107,16 @@ bool File::isHidden() const } //============================================================================== -static const File juce_readlink (const char* const utf8, const File& defaultFile) +static const File juce_readlink (const String& file, const File& defaultFile) { const int size = 8192; HeapBlock buffer; buffer.malloc (size + 4); - const size_t numBytes = readlink (utf8, buffer, size); + const size_t numBytes = readlink (file.toUTF8(), buffer, size); if (numBytes > 0 && numBytes <= size) - return File (String::fromUTF8 (buffer, (int) numBytes)); + return File (file).getSiblingFile (String::fromUTF8 (buffer, (int) numBytes)); return defaultFile; } diff --git a/src/native/windows/juce_win32_ActiveXComponent.cpp b/src/native/windows/juce_win32_ActiveXComponent.cpp index f42d614377..881c020fc3 100644 --- a/src/native/windows/juce_win32_ActiveXComponent.cpp +++ b/src/native/windows/juce_win32_ActiveXComponent.cpp @@ -105,8 +105,11 @@ namespace ActiveXHelpers HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo) { - *lplpFrame = frame; - *lplpDoc = 0; + /* Note: if you call AddRef on the frame here, then some types of object (e.g. web browser control) cause leaks.. + If you don't call AddRef then others crash (e.g. QuickTime).. Bit of a catch-22, so letting it leak is probably preferable. + */ + if (lplpFrame != 0) { frame->AddRef(); *lplpFrame = frame; } + if (lplpDoc != 0) *lplpDoc = 0; lpFrameInfo->fMDIApp = FALSE; lpFrameInfo->hwndFrame = window; lpFrameInfo->haccel = 0; @@ -213,7 +216,7 @@ namespace ActiveXHelpers //============================================================================== class ActiveXControlComponent::Pimpl : public ComponentMovementWatcher { - ActiveXControlComponent* const owner; + ActiveXControlComponent& owner; bool wasShowing; public: @@ -223,10 +226,10 @@ public: IOleObject* control; //============================================================================== - Pimpl (HWND hwnd, ActiveXControlComponent* const owner_) - : ComponentMovementWatcher (owner_), + Pimpl (HWND hwnd, ActiveXControlComponent& owner_) + : ComponentMovementWatcher (&owner_), owner (owner_), - wasShowing (owner_ != 0 && owner_->isShowing()), + wasShowing (owner_.isShowing()), controlHWND (0), storage (new ActiveXHelpers::JuceIStorage()), clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)), @@ -249,24 +252,24 @@ public: //============================================================================== void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) { - Component* const topComp = owner->getTopLevelComponent(); + Component* const topComp = owner.getTopLevelComponent(); if (topComp->getPeer() != 0) { - const Point pos (owner->relativePositionToOtherComponent (topComp, Point())); + const Point pos (owner.relativePositionToOtherComponent (topComp, Point())); - owner->setControlBounds (Rectangle (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight())); + owner.setControlBounds (Rectangle (pos.getX(), pos.getY(), owner.getWidth(), owner.getHeight())); } } void componentPeerChanged() { - const bool isShowingNow = owner->isShowing(); + const bool isShowingNow = owner.isShowing(); if (wasShowing != isShowingNow) { wasShowing = isShowingNow; - owner->setControlVisible (isShowingNow); + owner.setControlVisible (isShowingNow); } componentMovedOrResized (true, true); @@ -356,7 +359,7 @@ bool ActiveXControlComponent::createControl (const void* controlIID) const Point pos (relativePositionToOtherComponent (getTopLevelComponent(), Point())); HWND hwnd = (HWND) peer->getNativeHandle(); - ScopedPointer newControl (new Pimpl (hwnd, this)); + ScopedPointer newControl (new Pimpl (hwnd, *this)); HRESULT hr; if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0, diff --git a/src/native/windows/juce_win32_AudioCDReader.cpp b/src/native/windows/juce_win32_AudioCDReader.cpp index 63cde0702e..68c572da1c 100644 --- a/src/native/windows/juce_win32_AudioCDReader.cpp +++ b/src/native/windows/juce_win32_AudioCDReader.cpp @@ -2163,7 +2163,7 @@ public: int getIntProperty (const LPOLESTR name, const int defaultReturn) const { ComSmartPtr prop; - if (FAILED (discRecorder->GetRecorderProperties (&prop))) + if (FAILED (discRecorder->GetRecorderProperties (prop.resetAndGetPointerAddress()))) return defaultReturn; PROPSPEC iPropSpec; @@ -2178,7 +2178,7 @@ public: bool setIntProperty (const LPOLESTR name, const int value) const { ComSmartPtr prop; - if (FAILED (discRecorder->GetRecorderProperties (&prop))) + if (FAILED (discRecorder->GetRecorderProperties (prop.resetAndGetPointerAddress()))) return false; PROPSPEC iPropSpec; diff --git a/src/native/windows/juce_win32_CameraDevice.cpp b/src/native/windows/juce_win32_CameraDevice.cpp index c2c0fb123c..6139643f52 100644 --- a/src/native/windows/juce_win32_CameraDevice.cpp +++ b/src/native/windows/juce_win32_CameraDevice.cpp @@ -55,7 +55,7 @@ public: if (FAILED (hr)) return; - hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl); + hr = graphBuilder.QueryInterface (IID_IMediaControl, mediaControl); if (FAILED (hr)) return; @@ -63,7 +63,7 @@ public: ComSmartPtr streamConfig; hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter, - IID_IAMStreamConfig, (void**) &streamConfig); + IID_IAMStreamConfig, (void**) streamConfig.resetAndGetPointerAddress()); if (streamConfig != 0) { @@ -94,7 +94,7 @@ public: if (FAILED (hr)) return; - hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber); + hr = sampleGrabberBase.QueryInterface (IID_ISampleGrabber, sampleGrabber); if (FAILED (hr)) return; @@ -106,16 +106,16 @@ public: sampleGrabber->SetMediaType (&mt); callback = new GrabberCallback (*this); - sampleGrabber->SetCallback (callback, 1); + hr = sampleGrabber->SetCallback (callback, 1); hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber")); if (FAILED (hr)) return; ComSmartPtr grabberInputPin; - if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture") - && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview") - && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin))) + if (! (getPin (smartTee, PINDIR_OUTPUT, smartTeeCaptureOutputPin, "capture") + && getPin (smartTee, PINDIR_OUTPUT, smartTeePreviewOutputPin, "preview") + && getPin (sampleGrabberBase, PINDIR_INPUT, grabberInputPin))) return; hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin); @@ -186,10 +186,10 @@ public: recordNextFrameTime = false; ComSmartPtr pin; - if (getPin (filter, PINDIR_OUTPUT, &pin)) + if (getPin (filter, PINDIR_OUTPUT, pin)) { ComSmartPtr pushSource; - HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource); + HRESULT hr = pin.QueryInterface (IID_IAMPushSource, pushSource); if (pushSource != 0) { @@ -259,7 +259,7 @@ public: if (SUCCEEDED (hr)) { ComSmartPtr fileSink; - hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink); + hr = asfWriter.QueryInterface (IID_IFileSinkFilter, fileSink); if (SUCCEEDED (hr)) { @@ -272,10 +272,10 @@ public: if (SUCCEEDED (hr)) { ComSmartPtr asfConfig; - hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig); + hr = asfWriter.QueryInterface (IID_IConfigAsfWriter, asfConfig); asfConfig->SetIndexMode (true); ComSmartPtr profileManager; - hr = WMCreateProfileManager (&profileManager); + hr = WMCreateProfileManager (profileManager.resetAndGetPointerAddress()); // This gibberish is the DirectShow profile for a video-only wmv file. String prof (" currentProfile; - hr = profileManager->LoadProfileByData ((const WCHAR*) prof, ¤tProfile); + hr = profileManager->LoadProfileByData ((const WCHAR*) prof, currentProfile.resetAndGetPointerAddress()); hr = asfConfig->ConfigureFilterUsingProfile (currentProfile); if (SUCCEEDED (hr)) { ComSmartPtr asfWriterInputPin; - if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01")) + if (getPin (asfWriter, PINDIR_INPUT, asfWriterInputPin, "Video Input 01")) { hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin); @@ -383,7 +383,7 @@ public: owner->addChangeListener (this); owner->addUser(); owner->viewerComps.add (this); - setSize (owner_->width, owner_->height); + setSize (owner->width, owner->height); } ~DShowCaptureViewerComp() @@ -544,14 +544,14 @@ private: return false; } - static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0) + static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, ComSmartPtr& result, const char* pinName = 0) { ComSmartPtr enumerator; ComSmartPtr pin; - filter->EnumPins (&enumerator); + filter->EnumPins (enumerator.resetAndGetPointerAddress()); - while (enumerator->Next (1, &pin, 0) == S_OK) + while (enumerator->Next (1, pin.resetAndGetPointerAddress(), 0) == S_OK) { PIN_DIRECTION dir; pin->QueryDirection (&dir); @@ -564,8 +564,7 @@ private: if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName))) { - pin->AddRef(); - *result = pin; + result = pin; return true; } } @@ -578,20 +577,20 @@ private: { ComSmartPtr in, out; - return getPin (first, PINDIR_OUTPUT, &out) - && getPin (second, PINDIR_INPUT, &in) + return getPin (first, PINDIR_OUTPUT, out) + && getPin (second, PINDIR_INPUT, in) && SUCCEEDED (graphBuilder->Connect (out, in)); } bool addGraphToRot() { ComSmartPtr rot; - if (FAILED (GetRunningObjectTable (0, &rot))) + if (FAILED (GetRunningObjectTable (0, rot.resetAndGetPointerAddress()))) return false; ComSmartPtr moniker; WCHAR buffer[128]; - HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker); + HRESULT hr = CreateItemMoniker (_T("!"), buffer, moniker.resetAndGetPointerAddress()); if (FAILED (hr)) return false; @@ -603,7 +602,7 @@ private: { ComSmartPtr rot; - if (SUCCEEDED (GetRunningObjectTable (0, &rot))) + if (SUCCEEDED (GetRunningObjectTable (0, rot.resetAndGetPointerAddress()))) rot->Revoke (graphRegistrationID); } @@ -737,22 +736,22 @@ static ComSmartPtr enumerateCameras (StringArray* const names, if (SUCCEEDED (hr)) { ComSmartPtr enumerator; - hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0); + hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, enumerator.resetAndGetPointerAddress(), 0); if (SUCCEEDED (hr) && enumerator != 0) { - ComSmartPtr captureFilter; ComSmartPtr moniker; ULONG fetched; - while (enumerator->Next (1, &moniker, &fetched) == S_OK) + while (enumerator->Next (1, moniker.resetAndGetPointerAddress(), &fetched) == S_OK) { - hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter); + ComSmartPtr captureFilter; + hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) captureFilter.resetAndGetPointerAddress()); if (SUCCEEDED (hr)) { ComSmartPtr propertyBag; - hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag); + hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) propertyBag.resetAndGetPointerAddress()); if (SUCCEEDED (hr)) { @@ -771,17 +770,12 @@ static ComSmartPtr enumerateCameras (StringArray* const names, { name = var.bstrVal; result = captureFilter; - captureFilter = 0; break; } ++index; } - - moniker = 0; } - - captureFilter = 0; } } } diff --git a/src/native/windows/juce_win32_Files.cpp b/src/native/windows/juce_win32_Files.cpp index 88454000c0..15655494b3 100644 --- a/src/native/windows/juce_win32_Files.cpp +++ b/src/native/windows/juce_win32_Files.cpp @@ -521,7 +521,7 @@ const File File::getLinkedTarget() const if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink))) { ComSmartPtr persistFile; - if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile))) + if (SUCCEEDED (shellLink.QueryInterface (IID_IPersistFile, persistFile))) { if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ)) && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI))) diff --git a/src/native/windows/juce_win32_NativeIncludes.h b/src/native/windows/juce_win32_NativeIncludes.h index 6fbb7ac041..8777328dc3 100644 --- a/src/native/windows/juce_win32_NativeIncludes.h +++ b/src/native/windows/juce_win32_NativeIncludes.h @@ -199,35 +199,54 @@ public: ComSmartPtr() throw() : p (0) {} ComSmartPtr (ComClass* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); } ComSmartPtr (const ComSmartPtr& p_) : p (p_.p) { if (p != 0) p->AddRef(); } - ~ComSmartPtr() { if (p != 0) p->Release(); } + ~ComSmartPtr() { release(); } operator ComClass*() const throw() { return p; } ComClass& operator*() const throw() { return *p; } - ComClass** operator&() throw() { return &p; } ComClass* operator->() const throw() { return p; } - ComClass* operator= (ComClass* const newP) + ComSmartPtr& operator= (ComClass* const newP) { if (newP != 0) newP->AddRef(); - if (p != 0) p->Release(); + release(); p = newP; - return newP; + return *this; } - ComClass* operator= (const ComSmartPtr& newP) { return operator= (newP.p); } + ComSmartPtr& operator= (const ComSmartPtr& newP) { return operator= (newP.p); } - HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext = CLSCTX_INPROC_SERVER) + // Releases and nullifies this pointer and returns its address + ComClass** resetAndGetPointerAddress() { -#ifndef __MINGW32__ - operator= (0); - return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof (ComClass), (void**) &p); -#else - return S_FALSE; -#endif + release(); + p = 0; + return &p; + } + + HRESULT CoCreateInstance (REFCLSID classUUID, DWORD dwClsContext = CLSCTX_INPROC_SERVER) + { + #ifndef __MINGW32__ + return ::CoCreateInstance (classUUID, 0, dwClsContext, __uuidof (ComClass), (void**) resetAndGetPointerAddress()); + #else + return E_NOTIMPL; + #endif + } + + template + HRESULT QueryInterface (REFCLSID classUUID, ComSmartPtr& destObject) const + { + if (p == 0) + return E_POINTER; + + return p->QueryInterface (classUUID, (void**) destObject.resetAndGetPointerAddress()); } private: ComClass* p; + + void release() { if (p != 0) p->Release(); } + + ComClass** operator&() throw(); // private to avoid it being used accidentally }; //============================================================================== diff --git a/src/native/windows/juce_win32_WASAPI.cpp b/src/native/windows/juce_win32_WASAPI.cpp index 1ee911cb59..51b2ea1c99 100644 --- a/src/native/windows/juce_win32_WASAPI.cpp +++ b/src/native/windows/juce_win32_WASAPI.cpp @@ -103,11 +103,11 @@ static const String getDeviceID (IMMDevice* const device) return s; } -static EDataFlow getDataFlow (IMMDevice* const device) +static EDataFlow getDataFlow (const ComSmartPtr& device) { EDataFlow flow = eRender; ComSmartPtr endPoint; - if (check (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint))) + if (check (device.QueryInterface (__uuidof (IMMEndpoint), endPoint))) (void) check (endPoint->GetDataFlow (&flow)); return flow;