Skip to content

Commit f65a888

Browse files
authored
Make StandardOleMarshalObject ComVisible (#118745)
1 parent 9fd7c39 commit f65a888

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Windows.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace System.Runtime.InteropServices
77
{
8+
[ComVisible(true)]
89
public class StandardOleMarshalObject : MarshalByRefObject, IMarshal
910
{
1011
private static readonly Guid CLSID_StdMarshal = new Guid("00000017-0000-0000-c000-000000000046");

src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<Compile Include="System\Runtime\InteropServices\ProgIdAttributeTests.cs" />
161161
<Compile Include="System\Runtime\InteropServices\RuntimeEnvironmentTests.cs" />
162162
<Compile Include="System\Runtime\InteropServices\SafeBufferTests.cs" />
163+
<Compile Include="System\Runtime\InteropServices\StandardOleMarshalObjectTests.cs" />
163164
<Compile Include="System\Runtime\InteropServices\StructLayoutAttributeTests.cs" />
164165
<Compile Include="System\Runtime\InteropServices\TypeIdentifierAttributeTests.cs" />
165166
<Compile Include="System\Runtime\InteropServices\UnknownWrapperTests.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Xunit;
5+
6+
namespace System.Runtime.InteropServices.Tests
7+
{
8+
[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
9+
public class StandardOleMarshalObjectTests
10+
{
11+
private static readonly Guid IID_IDispatch = new Guid("00020400-0000-0000-C000-000000000046");
12+
[Fact]
13+
public void CanGetIDispatchOfDerivedObject()
14+
{
15+
IntPtr disp = Marshal.GetIDispatchForObject(new DerivedObject());
16+
Assert.NotEqual(IntPtr.Zero, disp);
17+
Marshal.Release(disp);
18+
}
19+
20+
[Fact]
21+
public void CanQueryInterfaceForIDispatchOfDerivedObject()
22+
{
23+
IntPtr unk = Marshal.GetIUnknownForObject(new DerivedObject());
24+
Assert.NotEqual(IntPtr.Zero, unk);
25+
26+
int hr = Marshal.QueryInterface(unk, IID_IDispatch, out IntPtr disp);
27+
Assert.Equal(0, hr);
28+
Assert.NotEqual(IntPtr.Zero, disp);
29+
30+
Marshal.Release(disp);
31+
Marshal.Release(unk);
32+
}
33+
34+
[ComVisible(true)]
35+
public sealed class DerivedObject : StandardOleMarshalObject
36+
{
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)