-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Use GeneratedDllImport in Microsoft.Extensions.Hosting.WindowsServices, System.Drawing.Primitives, System.Management, System.Security.Cryptography.ProtectedData, System.Speech, System.Windows.Extensions #61949
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
Changes from 7 commits
923d766
c74d383
9fbcbaf
5d52cbb
1ef89ec
d0c9c52
8debe77
93baf88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Kernel32 | ||
| { | ||
| [Flags] | ||
| internal enum SnapshotFlags : uint | ||
| { | ||
| HeapList = 0x00000001, | ||
| Process = 0x00000002, | ||
| Thread = 0x00000004, | ||
| Module = 0x00000008, | ||
| Module32 = 0x00000010, | ||
| All = (HeapList | Process | Thread | Module), | ||
| Inherit = 0x80000000, | ||
| NoHeaps = 0x40000000 | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] | ||
| internal struct PROCESSENTRY32 | ||
| { | ||
| internal int dwSize; | ||
| internal int cntUsage; | ||
| internal int th32ProcessID; | ||
| internal IntPtr th32DefaultHeapID; | ||
| internal int th32ModuleID; | ||
| internal int cntThreads; | ||
| internal int th32ParentProcessID; | ||
| internal int pcPriClassBase; | ||
| internal int dwFlags; | ||
| [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] | ||
| internal string szExeFile; | ||
| } | ||
|
|
||
| // https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot | ||
elinor-fung marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] | ||
| internal static partial IntPtr CreateToolhelp32Snapshot(SnapshotFlags dwFlags, uint th32ProcessID); | ||
|
|
||
| #pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time | ||
| // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types. | ||
| // https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-process32first | ||
elinor-fung marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [DllImport(Libraries.Kernel32, SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)] | ||
| internal static extern bool Process32First(IntPtr hSnapshot, ref PROCESSENTRY32 lppe); | ||
|
|
||
| // https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-process32next | ||
elinor-fung marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [DllImport(Libraries.Kernel32, SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)] | ||
| internal static extern bool Process32Next(IntPtr hSnapshot, ref PROCESSENTRY32 lppe); | ||
| #pragma warning restore DLLIMPORTGENANALYZER015 | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,15 @@ | |
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
| using System.Runtime.InteropServices.ComTypes; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Ole32 | ||
| { | ||
| #pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time | ||
| // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid) | ||
| [DllImport(Libraries.Ole32)] | ||
| internal static extern int CoGetObjectContext([MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IntPtr ppv); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is COM, if it isn't too big of a change I suppose we could change this to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a bunch of similar things around Guid, so I figure we can just keep their existing signatures and do a pass when we enable it (it is already noted in #60595). |
||
| #pragma warning restore DLLIMPORTGENANALYZER015 | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class WinMM | ||
| { | ||
| // Enum equivalent to MMSYSERR_* | ||
| internal enum MMSYSERR : int | ||
| { | ||
| NOERROR = 0, | ||
| ERROR = (1), | ||
| BADDEVICEID = (2), | ||
| NOTENABLED = (3), | ||
| ALLOCATED = (4), | ||
| INVALHANDLE = (5), | ||
| NODRIVER = (6), | ||
| NOMEM = (7), | ||
| NOTSUPPORTED = (8), | ||
| BADERRNUM = (9), | ||
| INVALFLAG = (10), | ||
| INVALPARAM = (11), | ||
| HANDLEBUSY = (12), | ||
| INVALIDALIAS = (13), | ||
| BADDB = (14), | ||
| KEYNOTFOUND = (15), | ||
| READERROR = (16), | ||
| WRITEERROR = (17), | ||
| DELETEERROR = (18), | ||
| VALNOTFOUND = (19), | ||
| NODRIVERCB = (20), | ||
| LASTERROR = (20) | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class WinMM | ||
| { | ||
| /// <summary> | ||
| /// This function closes the specified waveform output device. | ||
| /// </summary> | ||
| /// <param name="hwo">Handle to the waveform-audio output device. If the function | ||
| /// succeeds, the handle is no longer valid after this call.</param> | ||
| /// <returns>MMSYSERR</returns> | ||
| [GeneratedDllImport(Libraries.WinMM)] | ||
| internal static partial MMSYSERR waveOutClose(IntPtr hwo); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class WinMM | ||
| { | ||
| #pragma warning disable CA1823 // unused fields | ||
| internal struct WAVEOUTCAPS | ||
| { | ||
| private ushort wMid; | ||
| private ushort wPid; | ||
| private uint vDriverVersion; | ||
| [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] | ||
| internal string szPname; | ||
| private uint dwFormats; | ||
| private ushort wChannels; | ||
| private ushort wReserved1; | ||
| private ushort dwSupport; | ||
| } | ||
| #pragma warning restore CA1823 | ||
|
|
||
| /// <summary> | ||
| /// This function queries a specified waveform device to determine its | ||
| /// capabilities. | ||
| /// </summary> | ||
| /// <param name="uDeviceID">Identifier of the waveform-audio output device. | ||
| /// It can be either a device identifier or a Handle to an open waveform-audio | ||
| /// output device.</param> | ||
| /// <param name="caps">Pointer to a WAVEOUTCAPS structure to be filled with | ||
| /// information about the capabilities of the device.</param> | ||
| /// <param name="cbwoc">Size, in bytes, of the WAVEOUTCAPS structure.</param> | ||
| /// <returns>MMSYSERR</returns> | ||
| #pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time | ||
| // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types. | ||
| [DllImport(Libraries.WinMM)] | ||
| internal static extern MMSYSERR waveOutGetDevCaps(IntPtr uDeviceID, ref WAVEOUTCAPS caps, int cbwoc); | ||
| #pragma warning restore DLLIMPORTGENANALYZER015 | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.