Skip to content

Commit

Permalink
Use IStorage*/IStream* Instead of Interface (#8105)
Browse files Browse the repository at this point in the history
* Use IStream* instead of Interface where appropriate

* Use IStorage* and Remove LockBytesWrapper

* Return accurate HRESULT for IPersistStorage Load/Save

* Add finalizer to AxHost.State
  • Loading branch information
lonitra authored Nov 8, 2022
1 parent 5af325e commit 5cfec9e
Show file tree
Hide file tree
Showing 23 changed files with 197 additions and 432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Globalization;
using System.Windows.Forms;
using Windows.Win32.System.Com;
using Windows.Win32.System.Com.StructuredStorage;
using static Interop;
using IComDataObject = System.Runtime.InteropServices.ComTypes.IDataObject;
Expand All @@ -24,19 +25,24 @@ private static TraceSwitch RichTextDebug

internal OleCallback(RichTextBox owner) => _owner = owner;

public HRESULT GetNewStorage(out IStorage.Interface storage)
public unsafe HRESULT GetNewStorage(out IStorage* storage)
{
Debug.WriteLineIf(RichTextDebug.TraceVerbose, "IRichTextBoxOleCallback::GetNewStorage");
using ComScope<ILockBytes> pLockBytes = new(null);
PInvoke.CreateILockBytesOnHGlobal(0, true, pLockBytes);

WinFormsComWrappers.LockBytesWrapper pLockBytes = Ole32.CreateILockBytesOnHGlobal(IntPtr.Zero, true);

storage = Ole32.StgCreateDocfileOnILockBytes(
fixed (IStorage** pStorage = &storage)
{
HRESULT result = PInvoke.StgCreateDocfileOnILockBytes(
pLockBytes,
Ole32.STGM.SHARE_EXCLUSIVE | Ole32.STGM.CREATE | Ole32.STGM.READWRITE);
STGM.STGM_SHARE_EXCLUSIVE | STGM.STGM_CREATE | STGM.STGM_READWRITE,
reserved: 0,
pStorage);

Debug.Assert(storage is not null, "storage is NULL!");
Debug.Assert(result.Succeeded, "storage is NULL!");

return HRESULT.S_OK;
return result;
}
}

public HRESULT GetInPlaceContext(IntPtr lplpFrame, IntPtr lplpDoc, IntPtr lpFrameInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ internal static class IID
// 1CF2B120-547D-101B-8E65-08002B2BD119
public static Guid IErrorInfo { get; } = new(0x1CF2B120, 0x547D, 0x101B, 0x8E, 0x65, 0x08, 0x00, 0x2B, 0x2B, 0xD1, 0x19);

// 0000000A-0000-0000-C000-000000000046
internal static Guid ILockBytes { get; } = new(0x0000000A, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

// 43826D1E-E718-42EE-BC55-A1E261C37BFE
internal static Guid IShellItem { get; } = new(0x43826D1E, 0xE718, 0x42EE, 0xBC, 0x55, 0xA1, 0xE2, 0x61, 0xC3, 0x7B, 0xFE);
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static partial class Interop
internal static partial class Ole32
{
/// <summary>
/// Type of the storage element. Used with <see cref="STATSTG"/>.
/// Type of the storage element. Used with <see cref="Windows.Win32.System.Com.STATSTG"/>.
/// <see href="https://docs.microsoft.com/en-us/windows/desktop/api/objidl/ne-objidl-tagstgty"/>
/// </summary>
public enum STGTY : uint
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static partial class Richedit
public unsafe interface IRichEditOleCallback
{
[PreserveSig]
HRESULT GetNewStorage(out IStorage.Interface? ret);
HRESULT GetNewStorage(out IStorage* storage);

[PreserveSig]
HRESULT GetInPlaceContext(IntPtr lplpFrame, IntPtr lplpDoc, IntPtr lpFrameInfo);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,6 @@ protected override object CreateObject(IntPtr externalComObject, CreateObjectFla
return new EnumFORMATETCWrapper(enumFormatEtcComObject);
}

Guid lockBytesIID = IID.ILockBytes;
hr = Marshal.QueryInterface(externalComObject, ref lockBytesIID, out IntPtr lockBytesComObject);
if (hr == S_OK)
{
Marshal.Release(externalComObject);
return new LockBytesWrapper(lockBytesComObject);
}

Guid enumVariantIID = IID.IEnumVariant;
hr = Marshal.QueryInterface(externalComObject, ref enumVariantIID, out IntPtr enumVariantComObject);
if (hr == S_OK)
Expand Down
4 changes: 4 additions & 0 deletions src/System.Windows.Forms.Primitives/src/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CreateEnhMetaFileW
CreateFontIndirectW
CreateHalftonePalette
CreateICW
CreateILockBytesOnHGlobal
CreateMenu
CreatePatternBrush
CreatePen
Expand Down Expand Up @@ -170,6 +171,7 @@ GetExitCodeThread
GetFocus
GetForegroundWindow
GetGuiResources
GetHGlobalFromILockBytes
GetIconInfo
GetKeyState
GetKeyboardState
Expand Down Expand Up @@ -505,6 +507,8 @@ STG_E_FILENOTFOUND
STG_E_INVALIDFLAG
STG_E_INVALIDFUNCTION
STG_E_INVALIDPOINTER
StgCreateDocfileOnILockBytes
StgOpenStorageOnILockBytes
StretchDIBits
SystemParametersInfo
SystemParametersInfoForDpi
Expand Down
3 changes: 3 additions & 0 deletions src/System.Windows.Forms/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
System.Windows.Forms.AxHost.State.Dispose() -> void
System.Windows.Forms.AxHost.State.~State() -> void
System.Windows.Forms.PrintPreviewControl.TabStop.get -> bool
System.Windows.Forms.PrintPreviewControl.TabStop.set -> void
System.Windows.Forms.PrintPreviewControl.TabStopChanged -> System.EventHandler?
Expand All @@ -6,3 +8,4 @@ override System.Windows.Forms.MaskedTextBox.CreateAccessibilityInstance() -> Sys
override System.Windows.Forms.MaskedTextBox.OnGotFocus(System.EventArgs! e) -> void
override System.Windows.Forms.MaskedTextBox.OnMouseDown(System.Windows.Forms.MouseEventArgs! e) -> void
override System.Windows.Forms.TextBox.CreateAccessibilityInstance() -> System.Windows.Forms.AccessibleObject!
virtual System.Windows.Forms.AxHost.State.Dispose(bool disposing) -> void
Loading

0 comments on commit 5cfec9e

Please sign in to comment.