Skip to content

Commit c47cc43

Browse files
committed
VB6 doesn't crash immediately, but crashes straight after that
adds a *complete* VB6 interop, implements some members, confirms GUIDs and enum types for ProjectsEvents and ComponentsEvents. Adds an extra exception handler for _hasPictureProperty. CommandBarButton events aren't wiring up, bacause Office 97 disn't have a click event on CommandBarButtons
1 parent 8540552 commit c47cc43

File tree

5 files changed

+59
-22
lines changed

5 files changed

+59
-22
lines changed

Rubberduck.VBEEditor/SafeComWrappers/Office.Core/CommandBarButton.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Drawing;
33
using System.Windows.Forms;
4+
using System.Runtime.InteropServices;
45
using Microsoft.CSharp.RuntimeBinder;
56
using Rubberduck.VBEditor.SafeComWrappers.MSForms;
67
using Rubberduck.VBEditor.SafeComWrappers.Office.Core.Abstract;
@@ -153,6 +154,11 @@ private bool HasPictureProperty
153154
_hasPictureProperty = false;
154155
}
155156

157+
catch (COMException)
158+
{
159+
_hasPictureProperty = false;
160+
}
161+
156162
return _hasPictureProperty.Value;
157163
}
158164
}

Rubberduck.VBEEditor/SafeComWrappers/VB6/VBComponents.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ namespace Rubberduck.VBEditor.SafeComWrappers.VB6
1313
{
1414
public class VBComponents : SafeComWrapper<VB.VBComponents>, IVBComponents
1515
{
16-
//TODO - This is currently the VBA Guid, and it need to be updated when VB6 support is added.
17-
private static readonly Guid VBComponentsEventsGuid = new Guid("0002E116-0000-0000-C000-000000000046");
16+
private static readonly Guid VBComponentsEventsGuid = new Guid("0002E193-0000-0000-C000-000000000046");
1817

19-
//TODO - These *should* be the same, but this should be verified.
2018
private enum ComponentEventDispId
2119
{
2220
ItemAdded = 1,

Rubberduck.VBEEditor/SafeComWrappers/VB6/VBE.cs

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
using System;
22
using System.Linq;
3+
using System.Runtime.InteropServices;
4+
using System.Text;
35
using Rubberduck.VBEditor.Application;
46
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
7+
using Rubberduck.VBEditor.SafeComWrappers.Office.Core;
58
using Rubberduck.VBEditor.SafeComWrappers.Office.Core.Abstract;
9+
using Rubberduck.VBEditor.WindowsApi;
610
using VB = Microsoft.VB6.Interop.VBIDE;
711

812
namespace Rubberduck.VBEditor.SafeComWrappers.VB6
@@ -21,59 +25,70 @@ public object HardReference
2125

2226
public string Version
2327
{
24-
get { return IsWrappingNullReference ? string.Empty : Target.get_Version(); }
28+
get { return IsWrappingNullReference ? string.Empty : Target.Version; }
2529
}
2630

2731
public ICodePane ActiveCodePane
2832
{
29-
get { throw new NotImplementedException(); }
30-
set { throw new NotImplementedException(); }
33+
get { return new CodePane(IsWrappingNullReference ? null : Target.ActiveCodePane); }
34+
set { if (!IsWrappingNullReference) Target.ActiveCodePane = (VB.CodePane)value.Target; }
3135
}
3236

3337
public IVBProject ActiveVBProject
3438
{
35-
get { throw new NotImplementedException(); }
36-
set { throw new NotImplementedException(); }
39+
get { return new VBProject(IsWrappingNullReference ? null : Target.ActiveVBProject); }
40+
set { if (!IsWrappingNullReference) Target.ActiveVBProject = (VB.VBProject)value.Target; }
3741
}
3842

3943
public IWindow ActiveWindow
4044
{
41-
get { throw new NotImplementedException(); }
45+
get { return new Window(IsWrappingNullReference ? null : Target.ActiveWindow); }
4246
}
4347

4448
public IAddIns AddIns
4549
{
46-
get { throw new NotImplementedException(); }
50+
get { return new AddIns(IsWrappingNullReference ? null : Target.Addins); }
4751
}
4852

4953
public ICodePanes CodePanes
5054
{
51-
get { throw new NotImplementedException(); }
55+
get { return new CodePanes(IsWrappingNullReference ? null : Target.CodePanes); }
5256
}
5357

5458
public ICommandBars CommandBars
5559
{
56-
get { throw new NotImplementedException(); }
60+
get { return new CommandBars(IsWrappingNullReference ? null : Target.CommandBars); }
5761
}
5862

5963
public IWindow MainWindow
6064
{
61-
get { throw new NotImplementedException(); }
65+
get
66+
{
67+
try
68+
{
69+
return new Window(IsWrappingNullReference ? null : Target.MainWindow);
70+
}
71+
catch (InvalidComObjectException)
72+
{
73+
return null;
74+
}
75+
}
6276
}
6377

6478
public IVBComponent SelectedVBComponent
6579
{
66-
get { throw new NotImplementedException(); }
80+
get { return new VBComponent(IsWrappingNullReference ? null : Target.SelectedVBComponent); }
6781
}
6882

6983
public IVBProjects VBProjects
7084
{
71-
get { return new VBProjects(IsWrappingNullReference ? null : Target.get_VBProjects()); }
85+
get { return new VBProjects(IsWrappingNullReference ? null : Target.VBProjects); }
7286
}
7387

7488
public IWindows Windows
7589
{
76-
get { throw new NotImplementedException(); }
90+
get { return new Windows(IsWrappingNullReference ? null : Target.Windows); }
91+
7792
}
7893

7994
//public override void Release(bool final = false)
@@ -91,7 +106,7 @@ public IWindows Windows
91106

92107
public override bool Equals(ISafeComWrapper<VB.VBE> other)
93108
{
94-
return IsEqualIfNull(other) || (other != null && other.Target.get_Version() == Version);
109+
return IsEqualIfNull(other) || (other != null && other.Target.Version == Version);
95110
}
96111

97112
public bool Equals(IVBE other)
@@ -111,7 +126,28 @@ public IHostApplication HostApplication()
111126

112127
public IWindow ActiveMDIChild()
113128
{
114-
throw new NotImplementedException();
129+
const string mdiClientClass = "MDIClient";
130+
const int maxCaptionLength = 512;
131+
132+
IntPtr mainWindow = (IntPtr)MainWindow.HWnd;
133+
134+
IntPtr mdiClient = NativeMethods.FindWindowEx(mainWindow, IntPtr.Zero, mdiClientClass, string.Empty);
135+
136+
IntPtr mdiChild = NativeMethods.GetTopWindow(mdiClient);
137+
StringBuilder mdiChildCaption = new StringBuilder();
138+
int captionLength = NativeMethods.GetWindowText(mdiChild, mdiChildCaption, maxCaptionLength);
139+
140+
if (captionLength > 0)
141+
{
142+
try
143+
{
144+
return Windows.FirstOrDefault(win => win.Caption == mdiChildCaption.ToString());
145+
}
146+
catch
147+
{
148+
}
149+
}
150+
return null;
115151
}
116152

117153
public bool IsInDesignMode

Rubberduck.VBEEditor/SafeComWrappers/VB6/VBProjects.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ namespace Rubberduck.VBEditor.SafeComWrappers.VB6
1111
{
1212
public class VBProjects : SafeComWrapper<VB.VBProjects>, IVBProjects
1313
{
14-
//TODO - This is currently the VBA Guid, and it need to be updated when VB6 support is added.
15-
private static readonly Guid VBProjectsEventsGuid = new Guid("0002E103-0000-0000-C000-000000000046");
14+
private static readonly Guid VBProjectsEventsGuid = new Guid("0002E190-0000-0000-C000-000000000046");
1615

17-
//TODO - These *should* be the same, but this should be verified.
1816
private enum ProjectEventDispId
1917
{
2018
ItemAdded = 1,
@@ -112,7 +110,6 @@ public override int GetHashCode()
112110
private bool _eventsAttached;
113111
private void AttachEvents()
114112
{
115-
throw new NotImplementedException("Correct the Guid (see comment above), verify the DispIds, then remove this throw.");
116113
if (!_eventsAttached && !IsWrappingNullReference)
117114
{
118115
_projectAdded = OnProjectAdded;

libs/Microsoft.VB6.Interop.VBIDE.dll

1 KB
Binary file not shown.

0 commit comments

Comments
 (0)