The resulting SetProcessWorkingSetSize cannot be entered as -1
wangfeijian opened this issue · comments
Actual behavior
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern winmdroot.Foundation.BOOL SetProcessWorkingSetSize(winmdroot.Foundation.HANDLE hProcess, nuint dwMinimumWorkingSetSize, nuint dwMaximumWorkingSetSize);
Parameter dwMinimumWorkingSetSize and dwMaximumWorkingSetSize maybe -1, but nuint can't enter -1.
Expected behavior
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern winmdroot.Foundation.BOOL SetProcessWorkingSetSize(winmdroot.Foundation.HANDLE hProcess, nint dwMinimumWorkingSetSize, nint dwMaximumWorkingSetSize);
Repro steps
Context
- CsWin32 version: [e.g.
0.4.422-beta
] - Win32Metadata version (if explicitly set by project):
- Target Framework: [e.g.
netstandard2.0
] LangVersion
(if explicitly set by project): [e.g.9
]
You'll need to use unchecked((nuint)(-1))
for this one. Both metadata and CsWin32 are doing the right thing here, the API is just quirky.
The documentation hints at this, too:
If both dwMinimumWorkingSetSize and dwMaximumWorkingSetSize have the value (SIZE_T)–1, the function removes as many pages as possible from the working set of the specified process.
SIZE_T is a unsigned __int64
or ULONG_PTR
on x64 targets.
You'll need to use
unchecked((nuint)(-1))
for this one. Both metadata and CsWin32 are doing the right thing here, the API is just quirky.The documentation hints at this, too:
If both dwMinimumWorkingSetSize and dwMaximumWorkingSetSize have the value (SIZE_T)–1, the function removes as many pages as possible from the working set of the specified process.
SIZE_T is a
unsigned __int64
orULONG_PTR
on x64 targets.
thank you! it works.