Skip to content

Commit 25604b9

Browse files
committed
Move the extension class and use constant range instead.
1 parent 8b0ee61 commit 25604b9

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

Rubberduck.Parsing/ComReflection/ComModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using VARDESC = System.Runtime.InteropServices.ComTypes.VARDESC;
1313
using CALLCONV = System.Runtime.InteropServices.ComTypes.CALLCONV;
1414
using Rubberduck.VBEditor.ComManagement.TypeLibs.Abstract;
15-
using Rubberduck.JunkDrawer.Hacks;
15+
using Rubberduck.VBEditor.ComManagement.TypeLibs.Utility;
1616

1717
namespace Rubberduck.Parsing.ComReflection
1818
{

Rubberduck.Parsing/VBA/ParseCoordinator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ private void ExecuteCommonParseActivities(IReadOnlyCollection<QualifiedModuleNam
336336

337337
//TODO: Remove the conditional compilation after loading from typelibs actually works.
338338
//TODO: Improve the handling to avoid host crashing. See https://github.com/rubberduck-vba/Rubberduck/issues/5217
339-
[Conditional("LOAD_USER_COM_PROJECTS")]
339+
// [Conditional("LOAD_USER_COM_PROJECTS")]
340340
private void ProcessUserComProjects(ref CancellationToken token, ref IReadOnlyCollection<QualifiedModuleName> toParse, ref HashSet<QualifiedModuleName> toReresolveReferences, ref IReadOnlyCollection<string> newProjectIds)
341341
{
342342
RefreshUserComProjects(toParse, newProjectIds);

Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeInfoConstantsCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System.Collections.Generic;
22
using System.Runtime.InteropServices.ComTypes;
3-
using Rubberduck.JunkDrawer.Hacks;
43
using Rubberduck.VBEditor.ComManagement.TypeLibs.Abstract;
54
using Rubberduck.VBEditor.ComManagement.TypeLibs.Unmanaged;
5+
using Rubberduck.VBEditor.ComManagement.TypeLibs.Utility;
66
using TYPEATTR = System.Runtime.InteropServices.ComTypes.TYPEATTR;
77
using VARDESC = System.Runtime.InteropServices.ComTypes.VARDESC;
88

Rubberduck.JunkDrawer/Hacks/VarDescExtensions.cs renamed to Rubberduck.VBEEditor/ComManagement/TypeLibs/Utility/VarDescExtensions.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,23 @@ public static class VarDescExtensions
1616
///
1717
/// There is a small but non-zero chance that there might be a valid pointer that happens to be only in high half of the address...
1818
/// in that case, it'll be wrong but since VBA is always writing <see cref="VARKIND.VAR_STATIC"/> to the <see cref="VARDESC.varkind"/>
19-
/// field, we're kind of stuck...
19+
/// field. To accommodate this unlikely possibility, we take advantage of VBA's other failure to comply with MS-OAUT specifications:
20+
/// None of its constants has a valid member ID. Normally they are assigned <c>MEMBER_NIL</c> which makes them useless for enumeration. To
21+
/// accommodate this, the TypeInfoWrapper in Rubberduck.VBEditor project will generate unique member IDs for those constants. Thus, we can use
22+
/// the same range to infer that it's a constant assigned by the TypeInfoWrapper.
2023
/// </remarks>
2124
/// <param name="varDesc">The <see cref="VARDESC"/> from a VBA <see cref="ITypeInfo"/></param>
2225
/// <returns>True if this is most likely a constant. False when it's definitely not.</returns>
2326
public static bool IsValidVBAConstant(this VARDESC varDesc)
2427
{
25-
return varDesc.varkind == VARKIND.VAR_STATIC && varDesc.desc.oInst != 0;
28+
// TODO: Move the function to a better home and avoid duplication of constants (see TypeInfoWrapper)
29+
const int _ourConstantsDispatchMemberIDRangeStart = unchecked((int)0xFEDC0000);
30+
const int _ourConstantsDispatchMemberIDRangeBitmaskCheck = unchecked((int)0xFFFF0000);
31+
const int _ourConstantsDispatchMemberIDIndexBitmask = unchecked((int)0x0000FFFF);
32+
if ((varDesc.memid & _ourConstantsDispatchMemberIDRangeBitmaskCheck) >= _ourConstantsDispatchMemberIDRangeStart)
33+
{
34+
return varDesc.varkind == VARKIND.VAR_STATIC && varDesc.desc.lpvarValue != 0;
35+
}
2636
}
2737
}
2838
}

0 commit comments

Comments
 (0)