microsoft / microsoft/win32metadata
Error in the return type of the `GetProp` and `RemoveProp` function
- Dominant language
- C++
- Stars
- 1.5k
- Forks
- 149
- Avg merge
- 5d 16h
- Merged PRs (30d)
- 4
Description
## Actual behavior
Win32Cs uses [SafeFileHandle](https://learn.microsoft.com/en-us/dotnet/api/microsoft.win32.safehandles.safefilehandle) as the return type for the [GetProp](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getpropw) and [RemoveProp](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-removepropw) functions.
## Expected behavior
The return type of these functions is an arbitrary `HANDLE`—not necessarily a file handle—and in fact, it could be any integer value.
Therefore, the most appropriate return type for the managed versions of these functions is `IntPtr` (or `UIntPtr`).
Even if reflecting the original signature where the return type is `HANDLE`, it should be [SafeHandle](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.safehandle).
In that case, its actual type is that the [IsInvalid](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.safehandle.isinvalid) property always returns `false`, and the [ReleaseHandle](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.safehandle.releasehandle) method does nothing.
## Repro steps
1. `NativeMethods.txt` content:
```
GetProp
RemoveProp
```
2. `NativeMethods.json` content (if present):
```json
{
"$schema": "https://aka.ms/CsWin32.schema.json",
"allowMarshaling": false
}
```
3. Any of your own code that should be shared?
none
### Context
- CsWin32 version: `0.3.269`
- Win32Metadata version (if explicitly set by project):
- Target Framework: `net10.0-windows10.0.19041.0`
- `LangVersion` (if explicitly set by project): `latest`
Contributor guide
Research direction
Reproduce the issue using the NativeMethods.txt entries for GetProp and RemoveProp, with the shown NativeMethods.json settings, then inspect the Win32 metadata definitions and generated managed signatures for those functions. Done means both functions no longer use SafeFileHandle and instead expose the appropriate arbitrary-handle representation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100