Skip to content

Commit 76cfd9a

Browse files
committed
Sort out dlls for different versions.
1 parent 20f8d3b commit 76cfd9a

File tree

4 files changed

+130
-13
lines changed

4 files changed

+130
-13
lines changed

Rubberduck.VBEEditor/VBERuntime/Settings/VBESettings.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
24
using Microsoft.Win32;
35
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
46
using Rubberduck.VBEditor.Utility;
@@ -7,26 +9,27 @@ namespace Rubberduck.VBEditor.VbeRuntime.Settings
79
{
810
public class VbeSettings : IVbeSettings
911
{
10-
private const string Vbe7SettingPath = @"HKEY_CURRENT_USER\Software\Microsoft\VBA\7.0\Common";
11-
private const string Vbe6SettingPath = @"HKEY_CURRENT_USER\Software\Microsoft\VBA\6.0\Common";
12+
private static readonly List<string> VbeVersions = new List<string> { "6.0", "7.0", "7.1" };
13+
private const string VbeSettingPathTemplate = @"HKEY_CURRENT_USER\Software\Microsoft\VBA\{0}\Common";
14+
private const string Vb6SettingPath = @"HKEY_CURRENT_USER\Software\Microsoft\VBA\Microsoft Visual Basic";
1215

1316
private readonly IRegistryWrapper _registry;
1417
private readonly string _activeRegistryRootPath;
15-
private readonly string[] _registryRootPaths = { Vbe7SettingPath, Vbe6SettingPath };
18+
1619

1720
public VbeSettings(IVBE vbe, IRegistryWrapper registry)
1821
{
1922
try
2023
{
21-
switch (VbeDllVersion.GetCurrentVersion(vbe))
24+
Version = VbeDllVersion.GetCurrentVersion(vbe);
25+
switch (Version)
2226
{
27+
case DllVersion.Vbe7:
2328
case DllVersion.Vbe6:
24-
Version = DllVersion.Vbe6;
25-
_activeRegistryRootPath = Vbe6SettingPath;
29+
_activeRegistryRootPath = string.Format(VbeSettingPathTemplate, vbe.Version);
2630
break;
27-
case DllVersion.Vbe7:
28-
Version = DllVersion.Vbe7;
29-
_activeRegistryRootPath = Vbe7SettingPath;
31+
case DllVersion.Vb98:
32+
_activeRegistryRootPath = Vb6SettingPath;
3033
break;
3134
default:
3235
Version = DllVersion.Unknown;
@@ -62,7 +65,10 @@ private bool ReadActiveRegistryPath(string keyName)
6265

6366
private void WriteAllRegistryPaths(string keyName, bool value)
6467
{
65-
foreach (var path in _registryRootPaths)
68+
var paths = VbeVersions.Select(version => string.Format(VbeSettingPathTemplate, version))
69+
.Union(new[] {Vb6SettingPath});
70+
71+
foreach (var path in paths)
6672
{
6773
if (DWordToBooleanConverter(path, keyName) != null)
6874
{

Rubberduck.VBEEditor/VBERuntime/VBEDllVersion.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Rubberduck.VBEditor.VbeRuntime
55
public enum DllVersion
66
{
77
Unknown,
8+
Vb98,
89
Vbe6,
910
Vbe7
1011
}
@@ -18,7 +19,7 @@ public static DllVersion GetCurrentVersion(IVBE vbe)
1819
switch (int.Parse(vbe.Version.Split('.')[0]))
1920
{
2021
case 6:
21-
return DllVersion.Vbe6;
22+
return vbe.GetType().Namespace?.EndsWith("VB6") ?? false ? DllVersion.Vb98 : DllVersion.Vbe6;
2223
case 7:
2324
return DllVersion.Vbe7;
2425
default:
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using Rubberduck.VBEditor.VbeRuntime;
4+
5+
namespace Rubberduck.VBEditor.VBERuntime
6+
{
7+
internal class Vb6NativeApi : IVbeNativeApi
8+
{
9+
private const string _dllName = "vba6.dll";
10+
11+
public string DllName => _dllName;
12+
13+
[DllImport(_dllName)]
14+
private static extern int rtcDoEvents();
15+
public int DoEvents()
16+
{
17+
return rtcDoEvents();
18+
}
19+
20+
[DllImport(_dllName, SetLastError = true)]
21+
[return: MarshalAs(UnmanagedType.R4)]
22+
private static extern float rtcGetTimer();
23+
public float GetTimer()
24+
{
25+
return rtcGetTimer();
26+
}
27+
28+
[DllImport(_dllName, SetLastError = true)]
29+
private static extern void rtcGetDateVar(out object retVal);
30+
public void GetDateVar(out object retval)
31+
{
32+
rtcGetDateVar(out retval);
33+
}
34+
35+
[DllImport(_dllName, SetLastError = true)]
36+
private static extern void rtcGetPresentDate(out object retVal);
37+
public void GetPresentDate(out object retVal)
38+
{
39+
rtcGetPresentDate(out retVal);
40+
}
41+
42+
[DllImport(_dllName, SetLastError = true)]
43+
private static extern double rtcShell(IntPtr pathname, short windowstyle);
44+
public double Shell(IntPtr pathname, short windowstyle)
45+
{
46+
return rtcShell(pathname, windowstyle);
47+
}
48+
49+
[DllImport(_dllName, SetLastError = true)]
50+
private static extern void rtcGetTimeVar(out object retVal);
51+
public void GetTimeVar(out object retVal)
52+
{
53+
rtcGetTimeVar(out retVal);
54+
}
55+
56+
[DllImport(_dllName, SetLastError = true)]
57+
private static extern void rtcChangeDir(IntPtr path);
58+
public void ChangeDir(IntPtr path)
59+
{
60+
rtcChangeDir(path);
61+
}
62+
63+
[DllImport(_dllName, SetLastError = true)]
64+
private static extern void rtcChangeDrive(IntPtr driveletter);
65+
public void ChangeDrive(IntPtr driveletter)
66+
{
67+
rtcChangeDrive(driveletter);
68+
}
69+
70+
[DllImport(_dllName, SetLastError = true)]
71+
private static extern void rtcKillFiles(IntPtr pathname);
72+
public void KillFiles(IntPtr pathname)
73+
{
74+
rtcKillFiles(pathname);
75+
}
76+
77+
[DllImport(_dllName, SetLastError = true)]
78+
private static extern void rtcMakeDir(IntPtr path);
79+
public void MakeDir(IntPtr path)
80+
{
81+
rtcMakeDir(path);
82+
}
83+
84+
[DllImport(_dllName, SetLastError = true)]
85+
private static extern void rtcRemoveDir(IntPtr path);
86+
public void RemoveDir(IntPtr path)
87+
{
88+
rtcRemoveDir(path);
89+
}
90+
91+
[DllImport(_dllName, SetLastError = true)]
92+
private static extern void rtcBeep();
93+
public void Beep()
94+
{
95+
rtcBeep();
96+
}
97+
}
98+
}

Rubberduck.VBEEditor/VbeRuntime/VbeNativeApiAccessor.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
3+
using Rubberduck.VBEditor.VBERuntime;
34

45
namespace Rubberduck.VBEditor.VbeRuntime
56
{
@@ -37,6 +38,8 @@ private static IVbeNativeApi InitializeRuntime()
3738
return new VbeNativeApi7();
3839
case DllVersion.Vbe6:
3940
return new VbeNativeApi6();
41+
case DllVersion.Vb98:
42+
return new Vb6NativeApi();
4043
default:
4144
return DetermineVersion();
4245
}
@@ -61,8 +64,17 @@ private static IVbeNativeApi DetermineVersion()
6164
}
6265
catch
6366
{
64-
// we shouldn't be here.... Rubberduck is a VBA add-in, so how the heck could it have loaded without a VBE dll?!?
65-
throw new InvalidOperationException("Cannot execute DoEvents; the VBE dll could not be located.");
67+
try
68+
{
69+
runtime = new Vb6NativeApi();
70+
runtime.GetTimer();
71+
_version = DllVersion.Vb98;
72+
}
73+
catch
74+
{
75+
// we shouldn't be here.... Rubberduck is a VBA add-in, so how the heck could it have loaded without a VBE dll?!?
76+
throw new InvalidOperationException("Cannot execute DoEvents; the VBE dll could not be located.");
77+
}
6678
}
6779
}
6880

0 commit comments

Comments
 (0)