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

Cleanup OLEVERB #2313

Merged
merged 1 commit into from Nov 8, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Common/src/Interop/Ole32/Interop.OLEVERB.cs
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Ole32
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class OLEVERB
{
public OLEIVERB lVerb;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpszVerbName;
public User32.MF fuFlags;
public OLEVERBATTRIB grfAttribs;
}
}
}
18 changes: 18 additions & 0 deletions src/Common/src/Interop/Ole32/Interop.OLEVERBATTRIB.cs
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

internal static partial class Interop
{
internal static partial class Ole32
{
[Flags]
public enum OLEVERBATTRIB : uint
{
NEVERDIRTIES = 0x1,
ONCONTAINERMENU = 0x2,
}
}
}
17 changes: 0 additions & 17 deletions src/Common/src/NativeMethods.cs
Expand Up @@ -1586,21 +1586,6 @@ public override string ToString()
}
}

[StructLayout(LayoutKind.Sequential)/*leftover(noAutoOffset)*/]
public sealed class tagOLEVERB
{
public Ole32.OLEIVERB lVerb;

[MarshalAs(UnmanagedType.LPWStr)/*leftover(offset=4, customMarshal="UniStringMarshaller", lpszVerbName)*/]
public string lpszVerbName;

[MarshalAs(UnmanagedType.U4)/*leftover(offset=8, fuFlags)*/]
public int fuFlags;

[MarshalAs(UnmanagedType.U4)/*leftover(offset=12, grfAttribs)*/]
public int grfAttribs;
}

[StructLayout(LayoutKind.Sequential)]
public sealed class tagDVTARGETDEVICE
{
Expand Down Expand Up @@ -2057,8 +2042,6 @@ public class ActiveX
public const int ALIGN_LEFT = 0x3;
public const int ALIGN_RIGHT = 0x4;
public const int ALIGN_MAX = 0x4;
public const int OLEVERBATTRIB_NEVERDIRTIES = 0x1;
public const int OLEVERBATTRIB_ONCONTAINERMENU = 0x2;

public static Guid IID_IUnknown = new Guid("{00000000-0000-0000-C000-000000000046}");

Expand Down
34 changes: 18 additions & 16 deletions src/Common/src/UnsafeNativeMethods.cs
Expand Up @@ -983,7 +983,8 @@ public unsafe interface IOleObject
RECT* lprcPosRect);

[PreserveSig]
int EnumVerbs(out IEnumOLEVERB e);
HRESULT EnumVerbs(
out IEnumOLEVERB e);

[PreserveSig]
int OleUpdate();
Expand Down Expand Up @@ -1095,7 +1096,8 @@ public unsafe interface IOleInPlaceObjectWindowless
RECT* lprcPosRect);

[PreserveSig]
int EnumVerbs(out IEnumOLEVERB e);
HRESULT EnumVerbs(
out IEnumOLEVERB e);

[PreserveSig]
int OleUpdate();
Expand Down Expand Up @@ -1404,26 +1406,26 @@ public interface IConnectionPoint
int EnumConnections(out object pEnum);
}

[ComImport(), Guid("00000104-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IEnumOLEVERB
[ComImport]
[Guid("00000104-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public unsafe interface IEnumOLEVERB
{
[PreserveSig]
int Next(
[MarshalAs(UnmanagedType.U4)]
int celt,
[Out]
NativeMethods.tagOLEVERB rgelt,
[Out, MarshalAs(UnmanagedType.LPArray)]
int[] pceltFetched);
HRESULT Next(
uint celt,
Ole32.OLEVERB rgelt,
uint* pceltFetched);

[PreserveSig]
int Skip(
[In, MarshalAs(UnmanagedType.U4)]
int celt);
HRESULT Skip(
uint celt);

void Reset();
[PreserveSig]
HRESULT Reset();

void Clone(
[PreserveSig]
HRESULT Clone(
out IEnumOLEVERB ppenum);
}

Expand Down
Expand Up @@ -121,6 +121,8 @@
<Compile Include="..\..\Common\src\Interop\Ole32\Interop.OLEIVERB.cs" Link="Interop\Ole32\Interop.OLEIVERB.cs" />
<Compile Include="..\..\Common\src\Interop\Ole32\Interop.OLEMENUGROUPWIDTHS.cs" Link="Interop\Ole32\Interop.OLEMENUGROUPWIDTHS.cs" />
<Compile Include="..\..\Common\src\Interop\Ole32\Interop.OLEMISC.cs" Link="Interop\Ole32\Interop.OLEMISC.cs" />
<Compile Include="..\..\Common\src\Interop\Ole32\Interop.OLEVERB.cs" Link="Interop\Ole32\Interop.OLEVERB.cs" />
<Compile Include="..\..\Common\src\Interop\Ole32\Interop.OLEVERBATTRIB.cs" Link="Interop\Ole32\Interop.OLEVERBATTRIB.cs" />
<Compile Include="..\..\Common\src\Interop\Ole32\Interop.OLEWHICHMK.cs" Link="Interop\Ole32\Interop.OLEWHICHMK.cs" />
<Compile Include="..\..\Common\src\Interop\Ole32\Interop.PARAMDESC.cs" Link="Interop\Ole32\Interop.PARAMDESC.cs" />
<Compile Include="..\..\Common\src\Interop\Ole32\Interop.PARAMFLAG.cs" Link="Interop\Ole32\Interop.PARAMFLAG.cs" />
Expand Down Expand Up @@ -166,6 +168,7 @@
<Compile Include="..\..\Common\src\Interop\User32\Interop.IsProcessDPIAware.cs" Link="Interop\User32\Interop.IsProcessDPIAware.cs" />
<Compile Include="..\..\Common\src\Interop\User32\Interop.IsValidDpiAwarenessContext.cs" Link="Interop\User32\Interop.IsValidDpiAwarenessContext.cs" />
<Compile Include="..\..\Common\src\Interop\User32\Interop.MapWindowPoints.cs" Link="Interop\User32\Interop.MapWindowPoints.cs" />
<Compile Include="..\..\Common\src\Interop\User32\Interop.MF.cs" Link="Interop\User32\Interop.MF.cs" />
<Compile Include="..\..\Common\src\Interop\User32\Interop.MK.cs" Link="Interop\User32\Interop.MK.cs" />
<Compile Include="..\..\Common\src\Interop\User32\Interop.MSG.cs" Link="Interop\User32\Interop.MSG.cs" />
<Compile Include="..\..\Common\src\Interop\User32\Interop.MsgWaitForMultipleObjectsEx.cs" Link="Interop\User32\Interop.MsgWaitForMultipleObjectsEx.cs" />
Expand Down
Expand Up @@ -43,7 +43,7 @@ private unsafe class ActiveXImpl : MarshalByRefObject, IWindowTarget
private static readonly int s_adjustingRect = BitVector32.CreateMask(s_uiDead);

private static Point s_logPixels = Point.Empty;
private static NativeMethods.tagOLEVERB[] s_axVerbs;
private static Ole32.OLEVERB[] s_axVerbs;

private static int s_globalActiveXCount = 0;
private static bool s_checkedIE;
Expand Down Expand Up @@ -519,16 +519,16 @@ internal void Close(Ole32.OLECLOSE dwSaveOption)
/// <summary>
/// Returns a new verb enumerator.
/// </summary>
internal static int EnumVerbs(out UnsafeNativeMethods.IEnumOLEVERB e)
internal static HRESULT EnumVerbs(out UnsafeNativeMethods.IEnumOLEVERB e)
{
if (s_axVerbs == null)
{
NativeMethods.tagOLEVERB verbShow = new NativeMethods.tagOLEVERB();
NativeMethods.tagOLEVERB verbInplaceActivate = new NativeMethods.tagOLEVERB();
NativeMethods.tagOLEVERB verbUIActivate = new NativeMethods.tagOLEVERB();
NativeMethods.tagOLEVERB verbHide = new NativeMethods.tagOLEVERB();
NativeMethods.tagOLEVERB verbPrimary = new NativeMethods.tagOLEVERB();
NativeMethods.tagOLEVERB verbProperties = new NativeMethods.tagOLEVERB();
var verbShow = new Ole32.OLEVERB();
var verbInplaceActivate = new Ole32.OLEVERB();
var verbUIActivate = new Ole32.OLEVERB();
var verbHide = new Ole32.OLEVERB();
var verbPrimary = new Ole32.OLEVERB();
var verbProperties = new Ole32.OLEVERB();

verbShow.lVerb = Ole32.OLEIVERB.SHOW;
verbInplaceActivate.lVerb = Ole32.OLEIVERB.INPLACEACTIVATE;
Expand All @@ -537,9 +537,10 @@ internal static int EnumVerbs(out UnsafeNativeMethods.IEnumOLEVERB e)
verbPrimary.lVerb = Ole32.OLEIVERB.PRIMARY;
verbProperties.lVerb = Ole32.OLEIVERB.PROPERTIES;
verbProperties.lpszVerbName = SR.AXProperties;
verbProperties.grfAttribs = NativeMethods.ActiveX.OLEVERBATTRIB_ONCONTAINERMENU;
verbProperties.grfAttribs = Ole32.OLEVERBATTRIB.ONCONTAINERMENU;

s_axVerbs = new NativeMethods.tagOLEVERB[] {
s_axVerbs = new Ole32.OLEVERB[]
{
verbShow,
verbInplaceActivate,
verbUIActivate,
Expand All @@ -549,7 +550,7 @@ internal static int EnumVerbs(out UnsafeNativeMethods.IEnumOLEVERB e)
}

e = new ActiveXVerbEnum(s_axVerbs);
return NativeMethods.S_OK;
return HRESULT.S_OK;
}

/// <summary>
Expand Down
Expand Up @@ -4,6 +4,7 @@

using System.ComponentModel;
using System.Diagnostics;
using static Interop;

namespace System.Windows.Forms
{
Expand All @@ -14,18 +15,18 @@ public partial class Control
/// </summary>
private class ActiveXVerbEnum : UnsafeNativeMethods.IEnumOLEVERB
{
private readonly NativeMethods.tagOLEVERB[] _verbs;
private int _current;
private readonly Ole32.OLEVERB[] _verbs;
private uint _current;

internal ActiveXVerbEnum(NativeMethods.tagOLEVERB[] verbs)
internal ActiveXVerbEnum(Ole32.OLEVERB[] verbs)
{
_verbs = verbs;
_current = 0;
}

public int Next(int celt, NativeMethods.tagOLEVERB rgelt, int[] pceltFetched)
public unsafe HRESULT Next(uint celt, Ole32.OLEVERB rgelt, uint* pceltFetched)
{
int fetched = 0;
uint fetched = 0;

if (celt != 1)
{
Expand All @@ -46,46 +47,46 @@ public int Next(int celt, NativeMethods.tagOLEVERB rgelt, int[] pceltFetched)

if (pceltFetched != null)
{
pceltFetched[0] = fetched;
*pceltFetched = fetched;
}

#if DEBUG
if (CompModSwitches.ActiveX.TraceInfo)
{
Debug.WriteLine($"AxSource:IEnumOLEVERB::Next returning {fetched} verbs:");
Debug.Indent();
for (int i = _current - fetched; i < _current; i++)
for (uint i = _current - fetched; i < _current; i++)
{
Debug.WriteLine($"{i}: {_verbs[i].lVerb} {_verbs[i].lpszVerbName ?? string.Empty}");
}
Debug.Unindent();
}
#endif
return (celt == 0 ? NativeMethods.S_OK : NativeMethods.S_FALSE);
return (celt == 0 ? HRESULT.S_OK : HRESULT.S_FALSE);
}

public int Skip(int celt)
public HRESULT Skip(uint celt)
{
if (_current + celt < _verbs.Length)
{
_current += celt;
return NativeMethods.S_OK;
}
else
{
_current = _verbs.Length;
return NativeMethods.S_FALSE;
return HRESULT.S_OK;
}

_current = (uint)_verbs.Length;
return HRESULT.S_FALSE;
}

public void Reset()
public HRESULT Reset()
{
_current = 0;
return HRESULT.S_OK;
}

public void Clone(out UnsafeNativeMethods.IEnumOLEVERB ppenum)
public HRESULT Clone(out UnsafeNativeMethods.IEnumOLEVERB ppenum)
{
ppenum = new ActiveXVerbEnum(_verbs);
return HRESULT.S_OK;
}
}
}
Expand Down
Expand Up @@ -14021,7 +14021,7 @@ int UnsafeNativeMethods.IOleObject.GetClipboardData(int dwReserved, out IComData
}
}

int UnsafeNativeMethods.IOleObject.EnumVerbs(out UnsafeNativeMethods.IEnumOLEVERB e)
HRESULT UnsafeNativeMethods.IOleObject.EnumVerbs(out UnsafeNativeMethods.IEnumOLEVERB e)
{
Debug.WriteLineIf(CompModSwitches.ActiveX.TraceInfo, "AxSource:EnumVerbs");
return ActiveXImpl.EnumVerbs(out e);
Expand Down