Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

SetupApi: Add new methods #464

Merged
merged 7 commits into from
Jul 1, 2020
Merged

SetupApi: Add new methods #464

merged 7 commits into from
Jul 1, 2020

Conversation

qmfrederik
Copy link
Contributor

  • SetupDiCreateDeviceInfoList
  • SetupDiOpenDeviceInfo
  • SetupDiSetSelectedDevice
  • SetupDiGetDeviceInstallParams
  • SetupDiSetDeviceInstallParams
  • SetupDiBuildDriverInfoList
  • SetupDiEnumDriverInfo
  • SetupDiSetSelectedDriver

- SetupDiCreateDeviceInfoList
- SetupDiOpenDeviceInfo
- SetupDiSetSelectedDevice
- SetupDiGetDeviceInstallParams
- SetupDiSetDeviceInstallParams
- SetupDiBuildDriverInfoList
- SetupDiEnumDriverInfo
- SetupDiSetSelectedDriver
@qmfrederik qmfrederik mentioned this pull request Jun 29, 2020
Copy link
Collaborator

@AArnott AArnott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing! I have several comments but will be happy to merge when they're resolved.

/// <seealso href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff550956(v=vs.85).aspx"/>
[DllImport(nameof(SetupApi), SetLastError = true)]
public static unsafe extern SafeDeviceInfoSetHandle SetupDiCreateDeviceInfoList(
Guid* classGuid,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add [Friendly(FriendlyFlags.In | FriendlyFlags.Optional)] on this parameter so that we get friendly overloads including (I suspect) in Guid so that you can naturally pass a GUID in, while still retaining the ability to pass in null on this overload.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've added these flags. You now get overloads for Guid* and Guid?, which means that you need to cast null to either of these types.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which means that you need to cast null to either of these types.

Ya, that's unfortunate, but not exactly a new problem either in general.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: style-wise we define a parameter with its attribute on one line.

string deviceInstanceId,
IntPtr parent,
OpenFlags openFlags,
ref SP_DEVINFO_DATA deviceInfoData);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc indicates this last parameter is optional and can be null. Can you please change this parameter to:

[Friendly(FriendlyFlags.Bidirectional | FriendlyFlags.Optional)] SP_DEVINFO_DATA*

I believe we'll still generate a ref Struct overload, but folks can then also pass null as an argument instead.
BTW, this won't work if SP_DEVINFO_DATA has MarshalAs attributed fields on it, which is why we also discourage those attributes in structs, also mentioned in our contributing doc. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter is not optional, so I've changed the argument to [Friendly(FriendlyFlags.Bidirectional)] SP_DEVINFO_DATA*

Comment on lines 363 to 364
ref SP_DEVINFO_DATA devceInfoData,
ref SP_DEVINSTALL_PARAMS deviceInstallParams);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect similar corrections to what I describe above apply here.

@qmfrederik
Copy link
Contributor Author

Thanks, @AArnott. I think I've addressed the first round of feedback, let me know if you have further comments.

Copy link
Collaborator

@AArnott AArnott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very close. Thanks again.

/// <seealso href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff550956(v=vs.85).aspx"/>
[DllImport(nameof(SetupApi), SetLastError = true)]
public static unsafe extern SafeDeviceInfoSetHandle SetupDiCreateDeviceInfoList(
Guid* classGuid,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: style-wise we define a parameter with its attribute on one line.

@qmfrederik
Copy link
Contributor Author

@AArnott Allright, looks like CI is green on this one.

@AArnott AArnott merged commit c3716e0 into dotnet:master Jul 1, 2020
@qmfrederik qmfrederik deleted the features/setupapi branch July 1, 2020 21:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants