-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 GeneratedDllImport in Microsoft.Extensions.Hosting.WindowsServices, System.Drawing.Primitives, System.Management, System.Security.Cryptography.ProtectedData, System.Speech, System.Windows.Extensions #61949
Merged
elinor-fung
merged 8 commits into
dotnet:main
from
elinor-fung:convertSystemWindowsExtensions
Nov 23, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
923d766
Use GeneratedDllImport in System.Windows.Extensions
elinor-fung c74d383
Move System.Speech p/invokes into common directory
elinor-fung 9fbcbaf
Use GeneratedDllImport in System.Speech
elinor-fung 5d52cbb
System.Security.Cryptography.ProtectedData
elinor-fung 1ef89ec
Microsoft.Extensions.Hosting.WindowsServices
elinor-fung d0c9c52
System.Management
elinor-fung 8debe77
System.Drawing.Primitives
elinor-fung 93baf88
PR feedback
elinor-fung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateToolhelp32Snapshot.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/windows/desktop/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot | ||
[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/windows/desktop/api/tlhelp32/nf-tlhelp32-process32first | ||
[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/windows/desktop/api/tlhelp32/nf-tlhelp32-process32next | ||
[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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/libraries/Common/src/Interop/Windows/WinMm/Interop.MMSYSERR.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/libraries/Common/src/Interop/Windows/WinMm/Interop.waveOutClose.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/libraries/Common/src/Interop/Windows/WinMm/Interop.waveOutGetDevCaps.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
Guid*
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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).