Skip to content

Commit

Permalink
Changes following PR comments and SE chat
Browse files Browse the repository at this point in the history
  • Loading branch information
mansellan committed Apr 17, 2018
1 parent 9137972 commit 4e5aff0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 45 deletions.
Expand Up @@ -11,9 +11,9 @@ public abstract class SafeRedirectedEventedComWrapper<TSource, TEventSource, TEv
{
private const int NotAdvising = 0;
private readonly object _lock = new object();
private TEventSource _eventSource; // The event source
private IConnectionPoint _icp; // The connection point
private int _cookie = NotAdvising; // The cookie for the connection
private readonly TEventSource _eventSource;

protected SafeRedirectedEventedComWrapper(TSource target, TEventSource eventSource, bool rewrapping = false) : base(target, rewrapping)
{
Expand All @@ -23,7 +23,6 @@ protected SafeRedirectedEventedComWrapper(TSource target, TEventSource eventSour
protected override void Dispose(bool disposing)
{
DetachEvents();
Marshal.ReleaseComObject(_eventSource);
base.Dispose(disposing);
}

Expand Down Expand Up @@ -75,7 +74,9 @@ public void DetachEvents()
}

Marshal.ReleaseComObject(_icp);
Marshal.ReleaseComObject(_eventSource);
_icp = null;
_eventSource = null;
}
}
}
Expand Down
47 changes: 4 additions & 43 deletions Rubberduck.VBEditor.VB6/SafeComWrappers/Office/CommandBarButton.cs
Expand Up @@ -107,50 +107,11 @@ public void ApplyIcon()
return;
}

if (!HasPictureProperty)
using (var image = CreateTransparentImage(Picture))
{
using (var image = CreateTransparentImage(Picture))
{
Clipboard.SetImage(image);
Button.PasteFace();
Clipboard.Clear();
}
return;
}
}

private bool? _hasPictureProperty;
private bool HasPictureProperty
{
get
{
if (IsWrappingNullReference)
{
return false;
}

if (_hasPictureProperty.HasValue)
{
return _hasPictureProperty.Value;
}

try
{
dynamic button = Button;
var picture = button.Picture;
_hasPictureProperty = true;
}
catch (RuntimeBinderException)
{
_hasPictureProperty = false;
}

catch (COMException)
{
_hasPictureProperty = false;
}

return _hasPictureProperty.Value;
Clipboard.SetImage(image);
Button.PasteFace();
Clipboard.Clear();
}
}

Expand Down

0 comments on commit 4e5aff0

Please sign in to comment.