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

Use IStorage*/IStream* Instead of Interface #8105

Merged
merged 4 commits into from
Nov 8, 2022
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
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!");
Tanya-Solyanik marked this conversation as resolved.
Show resolved Hide resolved

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