Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added DispID offset in case of ComVisible false methods #246

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/dscom.test/tests/MemIdTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,15 @@ public void IDispatchInterfaceWith3MethodsAndOneComVisibleFalse_MemIdAndVTableSi
using var method1 = testInterface!.GetFuncDescByName("Method1");
method1.Should().NotBeNull();
method1!.Value.oVft.Should().Be(0);
method1!.Value.memid.Should().Be((int)Constants.BASE_OLEAUT_DISPID);

using var method2 = testInterface!.GetFuncDescByName("Method2");
method2.Should().BeNull();

using var method3 = testInterface!.GetFuncDescByName("Method3");
method3.Should().NotBeNull();
method3!.Value.oVft.Should().Be(0);
method3!.Value.memid.Should().Be(((int)Constants.BASE_OLEAUT_DISPID) + 2);
}

[Fact]
Expand All @@ -491,13 +493,15 @@ public void IDispatchInterfaceWith3PropertiesAndOneComVisibleFalse_MemIdAndVTabl
using var method1 = testInterface!.GetFuncDescByName("Property1");
method1.Should().NotBeNull();
method1!.Value.oVft.Should().Be(0);
method1!.Value.memid.Should().Be((int)Constants.BASE_OLEAUT_DISPID);

using var method2 = testInterface!.GetFuncDescByName("Property2");
method2.Should().BeNull();

using var method3 = testInterface!.GetFuncDescByName("Property3", INVOKEKIND.INVOKE_PROPERTYGET);
method3.Should().NotBeNull();
method3!.Value.oVft.Should().Be(0);
method3!.Value.memid.Should().Be(((int)Constants.BASE_OLEAUT_DISPID) + 4);
}

[Fact]
Expand All @@ -522,13 +526,15 @@ public void DualInterfaceWith3MethodsAndOneComVisibleFalse_MemIdAndVTableSizeAre
using var method1 = testInterface!.GetFuncDescByName("Method1");
method1.Should().NotBeNull();
method1!.Value.oVft.Should().Be(56);
method1!.Value.memid.Should().Be((int)Constants.BASE_OLEAUT_DISPID);

using var method2 = testInterface!.GetFuncDescByName("Method2");
method2.Should().BeNull();

using var method3 = testInterface!.GetFuncDescByName("Method3");
method3.Should().NotBeNull();
method3!.Value.oVft.Should().Be(72);
method3!.Value.memid.Should().Be(((int)Constants.BASE_OLEAUT_DISPID) + 2);
}

[Fact]
Expand All @@ -553,13 +559,15 @@ public void DualInterfaceWith3PropertiesAndOneComVisibleFalse_MemIdAndVTableSize
using var method1 = testInterface!.GetFuncDescByName("Property1");
method1.Should().NotBeNull();
method1!.Value.oVft.Should().Be(56);
method1!.Value.memid.Should().Be((int)Constants.BASE_OLEAUT_DISPID);

using var method2 = testInterface!.GetFuncDescByName("Property2");
method2.Should().BeNull();

using var method3 = testInterface!.GetFuncDescByName("Property3", INVOKEKIND.INVOKE_PROPERTYGET);
method3.Should().NotBeNull();
method3!.Value.oVft.Should().Be(88);
method3!.Value.memid.Should().Be(((int)Constants.BASE_OLEAUT_DISPID) + 4);
}

[Theory]
Expand Down
2 changes: 1 addition & 1 deletion src/dscom/DispatchIdCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void AddDispatchId(uint idGenerated, uint? idFromAttribute, MemberInfo m
}
}

private uint GetNextFreeDispId()
internal uint GetNextFreeDispId()
{
var dispId = _currentDispId;
_currentDispId++;
Expand Down
9 changes: 9 additions & 0 deletions src/dscom/writer/InterfaceWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,22 @@ private void CreateMethodWriters()
var functionIndex = 0;
foreach (var methodWriter in MethodWriters)
{
// A methodWriter can be null if ComVisible is false
if (methodWriter is not null)
{
methodWriter.FunctionIndex = functionIndex;
methodWriter.VTableOffset = VTableOffsetUserMethodStart + (index * IntPtr.Size);
DispatchIdCreator!.RegisterMember(methodWriter);
functionIndex += methodWriter.IsValid ? 1 : 0;
}
else
{
// In case of ComVisible false, we need to increment the the next free DispId
// This offset is needed to keep the DispId in sync with the VTable and the behavior of tlbexp.
DispatchIdCreator!.GetNextFreeDispId();
}

// Increment the index for the VTableOffset
index++;
}
}
Expand Down
Loading