Actual behavior
Win32Cs uses SafeFileHandle as the return type for the GetProp and RemoveProp 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.
In that case, its actual type is that the IsInvalid property always returns false, and the ReleaseHandle method does nothing.
Repro steps
NativeMethods.txt content:
NativeMethods.json content (if present):
{
"$schema": "https://aka.ms/CsWin32.schema.json",
"allowMarshaling": false
}
- 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
Actual behavior
Win32Cs uses SafeFileHandle as the return type for the GetProp and RemoveProp 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(orUIntPtr).Even if reflecting the original signature where the return type is
HANDLE, it should be SafeHandle.In that case, its actual type is that the IsInvalid property always returns
false, and the ReleaseHandle method does nothing.Repro steps
NativeMethods.txtcontent:NativeMethods.jsoncontent (if present):{ "$schema": "https://aka.ms/CsWin32.schema.json", "allowMarshaling": false }none
Context
0.3.269net10.0-windows10.0.19041.0LangVersion(if explicitly set by project):latest