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

Why do you set SetLastError = true and then dont use it ? #6

Open
Elmue opened this issue Dec 18, 2024 · 0 comments
Open

Why do you set SetLastError = true and then dont use it ? #6

Elmue opened this issue Dec 18, 2024 · 0 comments

Comments

@Elmue
Copy link

Elmue commented Dec 18, 2024

Your DLL Imports use SetLastError = true
but then after for example SetupDiGetClassDevs() returned INVALID_HANDLE_VALUE you write:

throw new Exception("SetupDiGetClassDevs() function failed.");

This will hide the cause of the failure from the user.
Why ?

Replace all your error handling like:

throw new Win32Exception(Marshal.GetLastWin32Error());

and the user will get a message with the cause of the failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant