@@ -1616,6 +1616,154 @@ public static int CopyTo(System.IntPtr thisPtr, System.IntPtr* pstm, ulong cb)
1616
1616
Assert . AreEqual ( expectedOutput , output ) ;
1617
1617
}
1618
1618
1619
+ [ TestMethod ]
1620
+ public void StructOutParameter ( )
1621
+ {
1622
+ string source = @"
1623
+ namespace Foo
1624
+ {
1625
+ using System.Threading;
1626
+ using System.Runtime.InteropServices;
1627
+
1628
+ public enum EnumType
1629
+ {
1630
+ }
1631
+
1632
+ public struct STATSTG
1633
+ {
1634
+ public object VariantValue;
1635
+ [MarshalAs(UnmanagedType.IUnknown)]
1636
+ public object UnknownValue;
1637
+ public EnumType EnumValue;
1638
+ }
1639
+
1640
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
1641
+ public interface IStr
1642
+ {
1643
+ void CopyTo(out STATSTG pstm);
1644
+ }
1645
+
1646
+ [ComCallableWrapper(typeof(IStr))]
1647
+ partial class C
1648
+ {
1649
+ }
1650
+ }" ;
1651
+ string output = this . GetGeneratedOutput ( source , NullableContextOptions . Disable ) ;
1652
+
1653
+ Assert . IsNotNull ( output ) ;
1654
+
1655
+ var expectedOutput = @"// <auto-generated>
1656
+ // Code generated by COM Proxy Code Generator.
1657
+ // Changes may cause incorrect behavior and will be lost if the code is
1658
+ // regenerated.
1659
+ // </auto-generated>
1660
+ #nullable enable
1661
+ using ComInterfaceDispatch = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch;
1662
+ using Marshal = System.Runtime.InteropServices.Marshal;
1663
+
1664
+ namespace Foo
1665
+ {
1666
+ [System.Runtime.Versioning.SupportedOSPlatform(""windows"")]
1667
+ unsafe partial class IStrProxy
1668
+ {
1669
+ [System.Runtime.InteropServices.UnmanagedCallersOnly]
1670
+ public static int CopyTo(System.IntPtr thisPtr, STATSTG_native* pstm)
1671
+ {
1672
+ try
1673
+ {
1674
+ var inst = ComInterfaceDispatch.GetInstance<global::Foo.IStr>((ComInterfaceDispatch*)thisPtr);
1675
+ global::Foo.STATSTG local_0;
1676
+ inst.CopyTo(out local_0);
1677
+ var local_0_VariantValue = local_0.VariantValue;
1678
+ WinFormsComInterop.InteropServices.Variant local_0_0 = new WinFormsComInterop.InteropServices.Variant();
1679
+ Marshal.GetNativeVariantForObject(local_0_VariantValue, (System.IntPtr)(WinFormsComInterop.InteropServices.Variant*)&local_0_0);
1680
+ pstm->VariantValue = local_0_0;
1681
+ var local_0_UnknownValue = local_0.UnknownValue;
1682
+ var local_0_1 = local_0_UnknownValue == null ? System.IntPtr.Zero : global::Foo.MarshalSupport.GetIUnknownForObject(local_0_UnknownValue);
1683
+ pstm->UnknownValue = local_0_1;
1684
+ var local_0_EnumValue = local_0.EnumValue;
1685
+ int local_0_2;
1686
+ pstm->EnumValue = local_0_EnumValue;
1687
+ }
1688
+ catch (System.Exception __e)
1689
+ {
1690
+ return __e.HResult;
1691
+ }
1692
+
1693
+ return 0; // S_OK;
1694
+ }
1695
+ }
1696
+ }" ;
1697
+ Assert . AreEqual ( expectedOutput , output ) ;
1698
+ }
1699
+
1700
+ [ TestMethod ]
1701
+ public void StructSTGMEDIUMOutParameter ( )
1702
+ {
1703
+ string source = @"
1704
+ namespace Foo
1705
+ {
1706
+ using System.Threading;
1707
+ using System.Runtime.InteropServices;
1708
+
1709
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
1710
+ public interface IStr
1711
+ {
1712
+ void CopyTo(out System.Runtime.InteropServices.ComTypes.STGMEDIUM pstm);
1713
+ }
1714
+
1715
+ [ComCallableWrapper(typeof(IStr))]
1716
+ partial class C
1717
+ {
1718
+ }
1719
+ }" ;
1720
+ string output = this . GetGeneratedOutput ( source , NullableContextOptions . Disable ) ;
1721
+
1722
+ Assert . IsNotNull ( output ) ;
1723
+
1724
+ var expectedOutput = @"// <auto-generated>
1725
+ // Code generated by COM Proxy Code Generator.
1726
+ // Changes may cause incorrect behavior and will be lost if the code is
1727
+ // regenerated.
1728
+ // </auto-generated>
1729
+ #nullable enable
1730
+ using ComInterfaceDispatch = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch;
1731
+ using Marshal = System.Runtime.InteropServices.Marshal;
1732
+
1733
+ namespace Foo
1734
+ {
1735
+ [System.Runtime.Versioning.SupportedOSPlatform(""windows"")]
1736
+ unsafe partial class IStrProxy
1737
+ {
1738
+ [System.Runtime.InteropServices.UnmanagedCallersOnly]
1739
+ public static int CopyTo(System.IntPtr thisPtr, STGMEDIUM_native* pstm)
1740
+ {
1741
+ try
1742
+ {
1743
+ var inst = ComInterfaceDispatch.GetInstance<global::Foo.IStr>((ComInterfaceDispatch*)thisPtr);
1744
+ global::System.Runtime.InteropServices.ComTypes.STGMEDIUM local_0;
1745
+ inst.CopyTo(out local_0);
1746
+ var local_0_tymed = local_0.tymed;
1747
+ int local_0_0;
1748
+ pstm->tymed = local_0_tymed;
1749
+ var local_0_unionmember = local_0.unionmember;
1750
+ pstm->unionmember = local_0_unionmember;
1751
+ var local_0_pUnkForRelease = local_0.pUnkForRelease;
1752
+ var local_0_2 = local_0_pUnkForRelease == null ? System.IntPtr.Zero : global::Foo.MarshalSupport.GetIUnknownForObject(local_0_pUnkForRelease);
1753
+ pstm->pUnkForRelease = local_0_2;
1754
+ }
1755
+ catch (System.Exception __e)
1756
+ {
1757
+ return __e.HResult;
1758
+ }
1759
+
1760
+ return 0; // S_OK;
1761
+ }
1762
+ }
1763
+ }" ;
1764
+ Assert . AreEqual ( expectedOutput , output ) ;
1765
+ }
1766
+
1619
1767
[ TestMethod ]
1620
1768
public void VariantOutParameter ( )
1621
1769
{
0 commit comments