Skip to content

Commit

Permalink
Make sure that AOT is working in .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
kant2002 committed Jun 16, 2024
1 parent 38dafef commit 8eec8f3
Show file tree
Hide file tree
Showing 32 changed files with 3,761 additions and 24 deletions.
2 changes: 2 additions & 0 deletions WinFormsComInterop/IAccessibleEnumWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace WinFormsComInterop;

#if !NET8_0_OR_GREATER
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleWindow))]
[RuntimeCallableWrapper(typeof(primitives::Interop.Oleaut32.IEnumVariant))]
#endif
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
partial class IAccessibleEnumWrapper
: global::Accessibility.IAccessible

Check failure on line 13 in WinFormsComInterop/IAccessibleEnumWrapper.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Accessibility' could not be found in the global namespace (are you missing an assembly reference?)
Expand Down
2 changes: 2 additions & 0 deletions WinFormsComInterop/IAccessibleWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace WinFormsComInterop;

#if !NET8_0_OR_GREATER
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleWindow))]
#endif
//[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleWindow))]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
partial class IAccessibleWrapper
Expand Down
3 changes: 3 additions & 0 deletions WinFormsComInterop/IConnectionPointWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace WinFormsComInterop;

#if NET8_0_OR_GREATER
#else
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IConnectionPoint))]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
partial class IConnectionPointWrapper
Expand All @@ -21,3 +23,4 @@ public IConnectionPointWrapper(IntPtr instance)
Marshal.Release(this.instance);
}
}
#endif
2 changes: 2 additions & 0 deletions WinFormsComInterop/IFileOpenDialogWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WinFormsComInterop;

#if !NET8_0_OR_GREATER
[RuntimeCallableWrapper(typeof(primitives::Interop.Shell32.IFileOpenDialog))]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
partial class IFileOpenDialogWrapper
Expand All @@ -21,3 +22,4 @@ public IFileOpenDialogWrapper(IntPtr instance)
Marshal.Release(this.instance);
}
}
#endif
2 changes: 2 additions & 0 deletions WinFormsComInterop/IFileSaveDialogWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WinFormsComInterop;

#if !NET8_0_OR_GREATER
[RuntimeCallableWrapper(typeof(primitives::Interop.Shell32.IFileSaveDialog))]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
partial class IFileSaveDialogWrapper
Expand All @@ -21,3 +22,4 @@ public IFileSaveDialogWrapper(IntPtr instance)
Marshal.Release(this.instance);
}
}
#endif
2 changes: 2 additions & 0 deletions WinFormsComInterop/IOleInPlaceActiveObjectWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WinFormsComInterop;

#if !NET8_0_OR_GREATER
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleInPlaceActiveObject))]
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleCommandTarget))]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
Expand All @@ -22,3 +23,4 @@ public IOleInPlaceActiveObjectWrapper(IntPtr instance)
Marshal.Release(this.instance);
}
}
#endif
2 changes: 2 additions & 0 deletions WinFormsComInterop/IOleInPlaceFrameWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WinFormsComInterop;

#if !NET8_0_OR_GREATER
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleInPlaceFrame))]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
partial class IOleInPlaceFrameWrapper
Expand All @@ -21,3 +22,4 @@ public IOleInPlaceFrameWrapper(IntPtr instance)
Marshal.Release(this.instance);
}
}
#endif
2 changes: 2 additions & 0 deletions WinFormsComInterop/IPictureWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WinFormsComInterop;

#if !NET8_0_OR_GREATER
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IPersistStream))]
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IPicture))]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
Expand All @@ -22,3 +23,4 @@ public IPictureWrapper(IntPtr instance)
Marshal.Release(this.instance);
}
}
#endif
6 changes: 4 additions & 2 deletions WinFormsComInterop/IWebBrowserWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

namespace WinFormsComInterop;

#if !NET8_0_OR_GREATER
[RuntimeCallableWrapper(typeof(primitives::Interop.Mshtml.IWebBrowser2))]
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleObject))]
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleControl))]
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleInPlaceObject))]
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleObject))]
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleInPlaceActiveObject))]
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IOleControl))]
[RuntimeCallableWrapper(typeof(primitives::Interop.Ole32.IConnectionPointContainer))]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public partial class IWebBrowserWrapper
Expand All @@ -26,3 +27,4 @@ public IWebBrowserWrapper(IntPtr instance)
Marshal.Release(this.instance);
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace WinFormsComInterop.WebView2;
[RuntimeCallableWrapper(typeof(webview2::Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller2))]
[RuntimeCallableWrapper(typeof(webview2::Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller3))]
[RuntimeCallableWrapper(typeof(webview2::Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller4))]
[RuntimeCallableWrapper(typeof(webview2::Microsoft.Web.WebView2.Core.Raw.ICoreWebView2PrivatePartialController))]
internal partial class ICoreWebView2ControllerWrapper
{
public readonly IntPtr instance;
Expand Down
59 changes: 48 additions & 11 deletions WinFormsComInterop/WinFormsComWrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,29 @@

namespace WinFormsComInterop
{
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IStream))]
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IServiceProvider))]
[ComCallableWrapper(typeof(primitives::Interop.UiaCore.IRawElementProviderSimple))]
//[ComCallableWrapper(typeof(primitives::Interop.UiaCore.IAccessibleEx))]
#if !NET8_0_OR_GREATER
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IServiceProvider))]
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IStream))]
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IDropTarget))]
[ComCallableWrapper(typeof(primitives::Interop.Mshtml.IDocHostUIHandler))]
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IStorage))]
[ComCallableWrapper(typeof(primitives::Interop.Richedit.IRichEditOleCallback))]
#endif
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IOleControlSite))]
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IOleInPlaceSite))]
#endif
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IOleContainer))]
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IOleClientSite))]
#if !NET8_0_OR_GREATER
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IOleInPlaceFrame))]
#endif
[ComCallableWrapper(typeof(primitives::Interop.SHDocVw.DWebBrowserEvents2))]
[ComCallableWrapper(typeof(primitives::Interop.Ole32.ISimpleFrameSite))]
#if !NET8_0_OR_GREATER
[ComCallableWrapper(typeof(primitives::Interop.Ole32.IPropertyNotifySink))]
[ComCallableWrapper(typeof(primitives::Interop.Shell32.IFileDialogEvents))]
#endif
#if !NET7_0_OR_GREATER
[ComCallableWrapper(typeof(System.Runtime.InteropServices.ComTypes.IEnumString))]
#endif
Expand All @@ -44,16 +48,18 @@ namespace WinFormsComInterop
public unsafe partial class WinFormsComWrappers : ComWrappers
{
static ComWrappers.ComInterfaceEntry* accessibleObjectEntry;
static ComWrappers.ComInterfaceEntry* primitivesStreamEntry;
#if !NET8_0_OR_GREATER
static ComWrappers.ComInterfaceEntry* primitivesStreamEntry;
static ComWrappers.ComInterfaceEntry* primitivesDropTargetEntry;
static ComWrappers.ComInterfaceEntry* storageEntry;
#endif
static ComWrappers.ComInterfaceEntry* richEditOleCallbackEntry;
static ComWrappers.ComInterfaceEntry* formsWebBrowserSiteEntry;
static ComWrappers.ComInterfaceEntry* formsWebBrowserContainerEntry;
static ComWrappers.ComInterfaceEntry* formsWebBrowserEventEntry;
#if !NET8_0_OR_GREATER
static ComWrappers.ComInterfaceEntry* formsFileDialogEventsEntry;
#endif
#if !NET7_0_OR_GREATER
static ComWrappers.ComInterfaceEntry* enumVariantEntry;
#endif
Expand Down Expand Up @@ -106,20 +112,22 @@ public unsafe partial class WinFormsComWrappers : ComWrappers
static WinFormsComWrappers()
{
accessibleObjectEntry = CreateAccessibleObjectEntry();
primitivesStreamEntry = CreatePrimitivesStreamEntry();
#if !NET7_0_OR_GREATER
enumVariantEntry = CreateEnumVariantEntry();
#endif

#if !NET8_0_OR_GREATER
primitivesStreamEntry = CreatePrimitivesStreamEntry();
primitivesDropTargetEntry = CreatePrimitivesDropTargetEntry();
storageEntry = CreatePrimitivesIStorageEntry();
#endif
richEditOleCallbackEntry = CreatePrimitivesIRichEditOleCallbackEntry();
#if !NET8_0_OR_GREATER
formsWebBrowserSiteEntry = CreateWebBrowserSiteEntry();
formsWebBrowserContainerEntry = CreateWebBrowserContainerEntry();
formsWebBrowserEventEntry = CreateWebBrowserEventEntry();
formsFileDialogEventsEntry = CreateFileDialogEventsEntry();
#endif
#if USE_WPF
oleDropTargetEntry = CreateOleDropTargetEntry();
winbaseTfContextEntry = CreateWinbaseITfContextEntry();
Expand Down Expand Up @@ -200,7 +208,6 @@ static WinFormsComWrappers()
return wrapperEntry;
}
#else

private static ComInterfaceEntry* CreatePrimitivesIRichEditOleCallbackEntry()
{
var vtblRaw = (System.IntPtr*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::WinFormsComInterop.WinFormsComWrappers), sizeof(System.IntPtr) * 13);
Expand All @@ -214,6 +221,14 @@ static WinFormsComWrappers()
wrapperEntry->Vtable = vtbl;
return wrapperEntry;
}

private static void CreatePrimitivesIServiceProviderProxyVtbl(out IntPtr vtbl)
{
var vtblRaw = (System.IntPtr*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::WinFormsComInterop.WinFormsComWrappers), sizeof(System.IntPtr) * 13);
GetIUnknownImpl(out vtblRaw[0], out vtblRaw[1], out vtblRaw[2]);
primitives::Windows.Win32.System.Com.IServiceProvider.PopulateVTable((primitives::Windows.Win32.System.Com.IServiceProvider.Vtbl*)vtblRaw);
vtbl = (System.IntPtr)vtblRaw;
}
#endif
private static ComInterfaceEntry* CreateAccessibleObjectEntry()
{
Expand All @@ -228,25 +243,22 @@ static WinFormsComWrappers()
wrapperEntry[1].Vtable = serviceProviderVtbl;
return wrapperEntry;
}
#if !NET8_0_OR_GREATER
private static ComInterfaceEntry* CreateWebBrowserSiteEntry()
{
CreatePrimitivesIOleControlSiteProxyVtbl(out var oleControlSiteVtbl);
#if !NET8_0_OR_GREATER
CreatePrimitivesIDocHostUIHandlerProxyVtbl(out var docHostUIHandlerVtbl);
#endif
CreatePrimitivesIOleInPlaceSiteProxyVtbl(out var oleInPlaceSiteVtbl);
CreatePrimitivesIPropertyNotifySinkProxyVtbl(out var propertyNotifySinkVtbl);
CreatePrimitivesIOleClientSiteProxyVtbl(out var oleClientSiteVtbl);
CreatePrimitivesISimpleFrameSiteProxyVtbl(out var simpleFrameSiteVtbl);
CreatePrimitivesIPropertyNotifySinkProxyVtbl(out var propertyNotifySinkVtbl);

var comInterfaceEntryMemory = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(WinFormsComWrappers), sizeof(ComInterfaceEntry) * 6);
var wrapperEntry = (ComInterfaceEntry*)comInterfaceEntryMemory.ToPointer();
wrapperEntry[0].IID = IID_IOleControlSite;
wrapperEntry[0].Vtable = oleControlSiteVtbl;
#if !NET8_0_OR_GREATER
wrapperEntry[1].IID = IID_IDocHostUIHandler;
wrapperEntry[1].Vtable = docHostUIHandlerVtbl;
#endif
wrapperEntry[2].IID = IID_IOleInPlaceSite;
wrapperEntry[2].Vtable = oleInPlaceSiteVtbl;
wrapperEntry[3].IID = IID_IOleClientSite;
Expand Down Expand Up @@ -301,6 +313,7 @@ static WinFormsComWrappers()
wrapperEntry->Vtable = vtbl;
return wrapperEntry;
}
#endif

#if !NET7_0_OR_GREATER
private static ComInterfaceEntry* CreateEnumVariantEntry()
Expand Down Expand Up @@ -409,11 +422,13 @@ static WinFormsComWrappers()
return formsWebBrowserEventEntry;
}

#if !NET8_0_OR_GREATER
if (obj is forms::System.Windows.Forms.FileDialog.VistaDialogEvents)
{
count = 1;
return formsFileDialogEventsEntry;
}
#endif

throw new NotImplementedException();
}
Expand Down Expand Up @@ -442,21 +457,34 @@ protected override object CreateObject(IntPtr externalComObject, CreateObjectFla
if (Marshal.QueryInterface(externalComObject, ref IID_IPicture, out var picturePtr) >= 0)
{
Marshal.Release(picturePtr);
#if NET8_0_OR_GREATER
throw new NotImplementedException();
#else
return new IPictureWrapper(externalComObject);
#endif
}

if (Marshal.QueryInterface(externalComObject, ref IID_IWebBrowser2, out var webBrowserPtr) >= 0)
{
Marshal.Release(webBrowserPtr);
#if NET8_0_OR_GREATER
throw new NotImplementedException();
#else
return new IWebBrowserWrapper(externalComObject);
#endif
}

if (Marshal.QueryInterface(externalComObject, ref IID_IConnectionPoint, out var connectionPointPtr) >= 0)
{
Marshal.Release(connectionPointPtr);
#if NET8_0_OR_GREATER
throw new NotImplementedException();
#else
return new IConnectionPointWrapper(externalComObject);
#endif
}

#if !NET8_0_OR_GREATER
if (Marshal.QueryInterface(externalComObject, ref IID_IFileOpenDialog, out var fileOpenDialogPtr) >= 0)
{
Marshal.Release(fileOpenDialogPtr);
Expand All @@ -468,6 +496,7 @@ protected override object CreateObject(IntPtr externalComObject, CreateObjectFla
Marshal.Release(fileSaveDialogPtr);
return new IFileSaveDialogWrapper(externalComObject);
}
#endif

if (Marshal.QueryInterface(externalComObject, ref IID_IDropTarget, out var dropTargetPtr) >= 0)
{
Expand All @@ -490,13 +519,21 @@ protected override object CreateObject(IntPtr externalComObject, CreateObjectFla
if (Marshal.QueryInterface(externalComObject, ref IID_IOleInPlaceActiveObject, out var inplaceActiveObjectPtr) >= 0)
{
Marshal.Release(inplaceActiveObjectPtr);
#if NET8_0_OR_GREATER
throw new NotImplementedException();
#else
return new IOleInPlaceActiveObjectWrapper(externalComObject);
#endif
}

if (Marshal.QueryInterface(externalComObject, ref IID_IOleInPlaceFrame, out var inplaceFramePtr) >= 0)
{
Marshal.Release(inplaceFramePtr);
#if NET8_0_OR_GREATER
throw new NotImplementedException();
#else
return new IOleInPlaceFrameWrapper(externalComObject);
#endif
}

GetIUnknownImpl(out IntPtr fpQueryInteface, out IntPtr fpAddRef, out IntPtr fpRelease);
Expand Down
Loading

0 comments on commit 8eec8f3

Please sign in to comment.