microsoft / microsoft/win32metadata
DEVINSTID in many calls should be const
- Dominant language
- C++
- Stars
- 1.5k
- Forks
- 149
- Avg merge
- 5d 16h
- Merged PRs (30d)
- 4
Description
## Actual behavior
Many configuration manager functions (e.g, `CM_Locate_DevNode`) take a `DEVINSTID` as parameter. This is defined as `WCHAR *` (for `DEVINSTID_W`). However, in all cases that I encountered the "string" is actually `const`. I don't know why the Windows API does not have a `const DEVINSTID` instead, but the result is that CSWin32 generates only `PWSTR` calls, requiring an `unsafe` context.
## Expected behavior
For those cases where `DEVINSTID` is in reality `const` (which could actually even be all cases), `string` overrides are generated, such that no `unsafe` context is required.
## Repro steps
1. `NativeMethods.txt` content:
```
CM_Locate_DevNode
```
2. `NativeMethods.json` content (if present):
```json
```
3. Any of your own code that should be shared?
https://github.com/dorssel/usbipd-win/blob/master/Usbipd/WindowsDevice.cs#L58-L67
### Context
- CsWin32 version: `0.3.264`
- Win32Metadata version (if explicitly set by project):
- Target Framework: `net10.0`
- `LangVersion` (if explicitly set by project): `14`
Contributor guide
Research direction
Start with the NativeMethods.txt reproduction for CM_Locate_DevNode and inspect the metadata used to generate its C# declaration. Compare the generated call with the WindowsDevice.cs example and check how similar DEVINSTID parameters are represented. Done means applicable parameters generate safe string overrides without requiring an unsafe context, with coverage for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- operating-systems, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100