Repository navigation
Add RAIIFree annotations for HidD_GetPreparsedData and related producers - #2376
Merged
Merged
Conversation
Annotate 25 producer out-parameters with the cleanup function that releases the handle they return, and mark 0 as the invalid value for the 8 handle typedefs that had no invalid value. The annotations go on the producers. Typedefs such as PHIDP_PREPARSED_DATA also describe caller-allocated buffers that the cleanup function must not free, so the typedefs carry no RAIIFree. Fixes #2375 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 62a90e5b-2b4b-46ac-b2e3-4a42da4989fc
Jevan Saks (jevansaks)
marked this pull request as ready for review
October 18, 2026 20:48
Jevan Saks (jevansaks)
requested review from
a team and
Vineeth Thomas Alex (vineeththomasalex)
as code owners
October 18, 2026 20:48
📋 API Surface Diff+33 additions / -25 deletions vs main branch (full validation run) Click to expand API diffdiff --git "a/bin\\baseline.apidump.cs" "b/bin\\current.apidump.cs"
index 6b9b9523..d73bad8d 100644
--- "a/bin\\baseline.apidump.cs"
+++ "b/bin\\current.apidump.cs"
@@ -34010,22 +34010,22 @@ namespace Windows.Win32.Devices.DeviceQuery;
public static class Apis
{
[DllImport ("api-ms-win-devices-query-l1-1-0.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern HRESULT DevCreateObjectQuery ([In] DEV_OBJECT_TYPE ObjectType, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 2)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 4)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out] HDEVQUERY* phDevQuery);
+ public unsafe static extern HRESULT DevCreateObjectQuery ([In] DEV_OBJECT_TYPE ObjectType, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 2)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 4)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out][RAIIFree ("DevCloseObjectQuery")] HDEVQUERY* phDevQuery);
[DllImport ("api-ms-win-devices-query-l1-1-1.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern HRESULT DevCreateObjectQueryEx ([In] DEV_OBJECT_TYPE ObjectType, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 2)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 4)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] uint cExtendedParameterCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 6)] DEV_QUERY_PARAMETER* pExtendedParameters, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out] HDEVQUERY* phDevQuery);
+ public unsafe static extern HRESULT DevCreateObjectQueryEx ([In] DEV_OBJECT_TYPE ObjectType, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 2)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 4)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] uint cExtendedParameterCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 6)] DEV_QUERY_PARAMETER* pExtendedParameters, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out][RAIIFree ("DevCloseObjectQuery")] HDEVQUERY* phDevQuery);
[DllImport ("api-ms-win-devices-query-l1-1-0.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern HRESULT DevCreateObjectQueryFromId ([In] DEV_OBJECT_TYPE ObjectType, [In][Const] PWSTR pszObjectId, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 3)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 5)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out] HDEVQUERY* phDevQuery);
+ public unsafe static extern HRESULT DevCreateObjectQueryFromId ([In] DEV_OBJECT_TYPE ObjectType, [In][Const] PWSTR pszObjectId, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 3)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 5)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out][RAIIFree ("DevCloseObjectQuery")] HDEVQUERY* phDevQuery);
[DllImport ("api-ms-win-devices-query-l1-1-1.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern HRESULT DevCreateObjectQueryFromIdEx ([In] DEV_OBJECT_TYPE ObjectType, [In][Const] PWSTR pszObjectId, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 3)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 5)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] uint cExtendedParameterCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 7)] DEV_QUERY_PARAMETER* pExtendedParameters, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out] HDEVQUERY* phDevQuery);
+ public unsafe static extern HRESULT DevCreateObjectQueryFromIdEx ([In] DEV_OBJECT_TYPE ObjectType, [In][Const] PWSTR pszObjectId, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 3)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 5)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] uint cExtendedParameterCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 7)] DEV_QUERY_PARAMETER* pExtendedParameters, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out][RAIIFree ("DevCloseObjectQuery")] HDEVQUERY* phDevQuery);
[DllImport ("api-ms-win-devices-query-l1-1-0.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern HRESULT DevCreateObjectQueryFromIds ([In] DEV_OBJECT_TYPE ObjectType, [In][Const][NotNullTerminated][NullNullTerminated] PWSTR pszzObjectIds, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 3)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 5)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out] HDEVQUERY* phDevQuery);
+ public unsafe static extern HRESULT DevCreateObjectQueryFromIds ([In] DEV_OBJECT_TYPE ObjectType, [In][Const][NotNullTerminated][NullNullTerminated] PWSTR pszzObjectIds, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 3)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 5)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out][RAIIFree ("DevCloseObjectQuery")] HDEVQUERY* phDevQuery);
[DllImport ("api-ms-win-devices-query-l1-1-1.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern HRESULT DevCreateObjectQueryFromIdsEx ([In] DEV_OBJECT_TYPE ObjectType, [In][Const][NotNullTerminated][NullNullTerminated] PWSTR pszzObjectIds, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 3)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 5)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] uint cExtendedParameterCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 7)] DEV_QUERY_PARAMETER* pExtendedParameters, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out] HDEVQUERY* phDevQuery);
+ public unsafe static extern HRESULT DevCreateObjectQueryFromIdsEx ([In] DEV_OBJECT_TYPE ObjectType, [In][Const][NotNullTerminated][NullNullTerminated] PWSTR pszzObjectIds, [In] uint QueryFlags, [In] uint cRequestedProperties, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 3)] DEVPROPCOMPKEY* pRequestedProperties, [In] uint cFilterExpressionCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 5)] DEVPROP_FILTER_EXPRESSION* pFilter, [In] uint cExtendedParameterCount, [Optional][In][Const][NativeArrayInfo (CountParamIndex = 7)] DEV_QUERY_PARAMETER* pExtendedParameters, [In] PDEV_QUERY_RESULT_CALLBACK pCallback, [Optional][In] void* pContext, [Out][RAIIFree ("DevCloseObjectQuery")] HDEVQUERY* phDevQuery);
[DllImport ("api-ms-win-devices-query-l1-1-0.dll", ExactSpelling = true, PreserveSig = false)]
public static extern void DevCloseObjectQuery ([In] HDEVQUERY hDevQuery);
@@ -34225,6 +34225,7 @@ using Windows.Win32.Foundation.Metadata;
namespace Windows.Win32.Devices.DeviceQuery;
+[InvalidHandleValue (0L)]
[NativeTypedef]
public struct HDEVQUERY
{
@@ -63482,7 +63483,7 @@ public static class Apis
public unsafe static extern void HidD_GetHidGuid ([Out] Guid* HidGuid);
[DllImport ("HID.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern BOOLEAN HidD_GetPreparsedData ([In] HANDLE HidDeviceObject, [Out] PHIDP_PREPARSED_DATA* PreparsedData);
+ public unsafe static extern BOOLEAN HidD_GetPreparsedData ([In] HANDLE HidDeviceObject, [Out][RAIIFree ("HidD_FreePreparsedData")] PHIDP_PREPARSED_DATA* PreparsedData);
[DllImport ("HID.dll", ExactSpelling = true, PreserveSig = false)]
public static extern BOOLEAN HidD_FreePreparsedData ([In] PHIDP_PREPARSED_DATA PreparsedData);
@@ -66481,6 +66482,7 @@ using Windows.Win32.Foundation.Metadata;
namespace Windows.Win32.Devices.HumanInterfaceDevice;
+[InvalidHandleValue (0L)]
[NativeTypedef]
public struct PHIDP_PREPARSED_DATA
{
@@ -472507,7 +472509,7 @@ public static class Apis
public unsafe static extern uint HttpGetServerCredentials ([In] PWSTR pwszUrl, [Out] PWSTR* ppwszUserName, [Out] PWSTR* ppwszPassword);
[DllImport ("WININET.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern uint HttpPushEnable ([In] void* hRequest, [In] HTTP_PUSH_TRANSPORT_SETTING* pTransportSetting, [Out] HTTP_PUSH_WAIT_HANDLE* phWait);
+ public unsafe static extern uint HttpPushEnable ([In] void* hRequest, [In] HTTP_PUSH_TRANSPORT_SETTING* pTransportSetting, [Out][RAIIFree ("HttpPushClose")] HTTP_PUSH_WAIT_HANDLE* phWait);
[DllImport ("WININET.dll", ExactSpelling = true, PreserveSig = false)]
public unsafe static extern uint HttpPushWait ([In] HTTP_PUSH_WAIT_HANDLE hWait, [In] HTTP_PUSH_WAIT_TYPE eType, [Optional][Out] HTTP_PUSH_NOTIFICATION_STATUS* pNotificationStatus);
@@ -494024,7 +494026,7 @@ public static class Apis
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
[Documentation ("https://learn.microsoft.com/windows/win32/api/winsafer/nf-winsafer-safercreatelevel")]
- public unsafe static extern BOOL SaferCreateLevel ([In] uint dwScopeId, [In] uint dwLevelId, [In] uint OpenFlags, [Out] SAFER_LEVEL_HANDLE* pLevelHandle, [Optional][Reserved] void* lpReserved);
+ public unsafe static extern BOOL SaferCreateLevel ([In] uint dwScopeId, [In] uint dwLevelId, [In] uint OpenFlags, [Out][RAIIFree ("SaferCloseLevel")] SAFER_LEVEL_HANDLE* pLevelHandle, [Optional][Reserved] void* lpReserved);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
@@ -494034,7 +494036,7 @@ public static class Apis
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
[Documentation ("https://learn.microsoft.com/windows/win32/api/winsafer/nf-winsafer-saferidentifylevel")]
- public unsafe static extern BOOL SaferIdentifyLevel ([In] uint dwNumProperties, [Optional][In][NativeArrayInfo (CountParamIndex = 0)] SAFER_CODE_PROPERTIES_V2* pCodeProperties, [Out] SAFER_LEVEL_HANDLE* pLevelHandle, [Optional][In] void* lpReserved);
+ public unsafe static extern BOOL SaferIdentifyLevel ([In] uint dwNumProperties, [Optional][In][NativeArrayInfo (CountParamIndex = 0)] SAFER_CODE_PROPERTIES_V2* pCodeProperties, [Out][RAIIFree ("SaferCloseLevel")] SAFER_LEVEL_HANDLE* pLevelHandle, [Optional][In] void* lpReserved);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
@@ -526823,7 +526825,7 @@ public static class Apis
[DllImport ("ncrypt.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows8.0")]
[Documentation ("https://learn.microsoft.com/windows/win32/api/ncryptprotect/nf-ncryptprotect-ncryptcreateprotectiondescriptor")]
- public unsafe static extern HRESULT NCryptCreateProtectionDescriptor ([In][Const] PWSTR pwszDescriptorString, [In] uint dwFlags, [Out] NCRYPT_DESCRIPTOR_HANDLE* phDescriptor);
+ public unsafe static extern HRESULT NCryptCreateProtectionDescriptor ([In][Const] PWSTR pwszDescriptorString, [In] uint dwFlags, [Out][RAIIFree ("NCryptCloseProtectionDescriptor")] NCRYPT_DESCRIPTOR_HANDLE* phDescriptor);
[DllImport ("ncrypt.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows8.0")]
@@ -526848,16 +526850,16 @@ public static class Apis
[DllImport ("ncrypt.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows8.0")]
[Documentation ("https://learn.microsoft.com/windows/win32/api/ncryptprotect/nf-ncryptprotect-ncryptstreamopentoprotect")]
- public unsafe static extern HRESULT NCryptStreamOpenToProtect ([In] NCRYPT_DESCRIPTOR_HANDLE hDescriptor, [In] uint dwFlags, [Optional][In] HWND hWnd, [In] NCRYPT_PROTECT_STREAM_INFO* pStreamInfo, [Out] NCRYPT_STREAM_HANDLE* phStream);
+ public unsafe static extern HRESULT NCryptStreamOpenToProtect ([In] NCRYPT_DESCRIPTOR_HANDLE hDescriptor, [In] uint dwFlags, [Optional][In] HWND hWnd, [In] NCRYPT_PROTECT_STREAM_INFO* pStreamInfo, [Out][RAIIFree ("NCryptStreamClose")] NCRYPT_STREAM_HANDLE* phStream);
[DllImport ("ncrypt.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows8.0")]
[Documentation ("https://learn.microsoft.com/windows/win32/api/ncryptprotect/nf-ncryptprotect-ncryptstreamopentounprotect")]
- public unsafe static extern HRESULT NCryptStreamOpenToUnprotect ([In] NCRYPT_PROTECT_STREAM_INFO* pStreamInfo, [In] uint dwFlags, [Optional][In] HWND hWnd, [Out] NCRYPT_STREAM_HANDLE* phStream);
+ public unsafe static extern HRESULT NCryptStreamOpenToUnprotect ([In] NCRYPT_PROTECT_STREAM_INFO* pStreamInfo, [In] uint dwFlags, [Optional][In] HWND hWnd, [Out][RAIIFree ("NCryptStreamClose")] NCRYPT_STREAM_HANDLE* phStream);
[DllImport ("ncrypt.dll", ExactSpelling = true, PreserveSig = false)]
[Documentation ("https://learn.microsoft.com/windows/win32/api/ncryptprotect/nf-ncryptprotect-ncryptstreamopentounprotectex")]
- public unsafe static extern HRESULT NCryptStreamOpenToUnprotectEx ([In] NCRYPT_PROTECT_STREAM_INFO_EX* pStreamInfo, [In] uint dwFlags, [Optional][In] HWND hWnd, [Out] NCRYPT_STREAM_HANDLE* phStream);
+ public unsafe static extern HRESULT NCryptStreamOpenToUnprotectEx ([In] NCRYPT_PROTECT_STREAM_INFO_EX* pStreamInfo, [In] uint dwFlags, [Optional][In] HWND hWnd, [Out][RAIIFree ("NCryptStreamClose")] NCRYPT_STREAM_HANDLE* phStream);
[DllImport ("ncrypt.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows8.0")]
@@ -606395,10 +606397,10 @@ public static class Apis
[DllImport ("KERNELBASE.dll", ExactSpelling = true, PreserveSig = false)]
[Documentation ("https://learn.microsoft.com/windows/win32/api/appmodel/nf-appmodel-addpackagedependency")]
- public unsafe static extern HRESULT AddPackageDependency ([In][Const] PWSTR packageDependencyId, [In] int rank, [In] AddPackageDependencyOptions options, [Out] PACKAGEDEPENDENCY_CONTEXT* packageDependencyContext, [Optional][Out] PWSTR* packageFullName);
+ public unsafe static extern HRESULT AddPackageDependency ([In][Const] PWSTR packageDependencyId, [In] int rank, [In] AddPackageDependencyOptions options, [Out][RAIIFree ("RemovePackageDependency")] PACKAGEDEPENDENCY_CONTEXT* packageDependencyContext, [Optional][Out] PWSTR* packageFullName);
[DllImport ("api-ms-win-appmodel-runtime-l1-1-7.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern HRESULT AddPackageDependency2 ([In][Const] PWSTR packageDependencyId, [In] int rank, [In] AddPackageDependencyOptions2 options, [Out] PACKAGEDEPENDENCY_CONTEXT* packageDependencyContext, [Optional][Out] PWSTR* packageFullName);
+ public unsafe static extern HRESULT AddPackageDependency2 ([In][Const] PWSTR packageDependencyId, [In] int rank, [In] AddPackageDependencyOptions2 options, [Out][RAIIFree ("RemovePackageDependency")] PACKAGEDEPENDENCY_CONTEXT* packageDependencyContext, [Optional][Out] PWSTR* packageFullName);
[DllImport ("KERNELBASE.dll", ExactSpelling = true, PreserveSig = false)]
[Documentation ("https://learn.microsoft.com/windows/win32/api/appmodel/nf-appmodel-removepackagedependency")]
@@ -606460,7 +606462,7 @@ public static class Apis
public unsafe static extern WIN32_ERROR AppPolicyGetCreateFileAccess ([In] HANDLE processToken, [Out] AppPolicyCreateFileAccess* policy);
[DllImport ("KERNEL32.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern HRESULT CreatePackageVirtualizationContext ([Optional][In][Const] PWSTR packageFamilyName, [Out] PACKAGE_VIRTUALIZATION_CONTEXT_HANDLE* context);
+ public unsafe static extern HRESULT CreatePackageVirtualizationContext ([Optional][In][Const] PWSTR packageFamilyName, [Out][RAIIFree ("ReleasePackageVirtualizationContext")] PACKAGE_VIRTUALIZATION_CONTEXT_HANDLE* context);
[DllImport ("KERNEL32.dll", ExactSpelling = true, PreserveSig = false)]
public unsafe static extern HRESULT ActivatePackageVirtualizationContext ([In] PACKAGE_VIRTUALIZATION_CONTEXT_HANDLE context, [Out] UIntPtr* cookie);
@@ -606472,7 +606474,7 @@ public static class Apis
public static extern void DeactivatePackageVirtualizationContext ([In] UIntPtr cookie);
[DllImport ("KERNEL32.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern HRESULT DuplicatePackageVirtualizationContext ([In] PACKAGE_VIRTUALIZATION_CONTEXT_HANDLE sourceContext, [Out] PACKAGE_VIRTUALIZATION_CONTEXT_HANDLE* destContext);
+ public unsafe static extern HRESULT DuplicatePackageVirtualizationContext ([In] PACKAGE_VIRTUALIZATION_CONTEXT_HANDLE sourceContext, [Out][RAIIFree ("ReleasePackageVirtualizationContext")] PACKAGE_VIRTUALIZATION_CONTEXT_HANDLE* destContext);
[DllImport ("KERNEL32.dll", ExactSpelling = true, PreserveSig = false)]
public static extern PACKAGE_VIRTUALIZATION_CONTEXT_HANDLE GetCurrentPackageVirtualizationContext ();
@@ -608444,6 +608446,7 @@ using Windows.Win32.Foundation.Metadata;
namespace Windows.Win32.Storage.Packaging.Appx;
+[InvalidHandleValue (0L)]
[NativeTypedef]
public struct PACKAGEDEPENDENCY_CONTEXT
{
@@ -608578,6 +608581,7 @@ using Windows.Win32.Foundation.Metadata;
namespace Windows.Win32.Storage.Packaging.Appx;
+[InvalidHandleValue (0L)]
[NativeTypedef]
public struct PACKAGE_VIRTUALIZATION_CONTEXT_HANDLE
{
@@ -609901,7 +609905,7 @@ public static class Apis
[DllImport ("PROJECTEDFSLIB.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows10.0.17763")]
[Documentation ("https://learn.microsoft.com/windows/win32/api/projectedfslib/nf-projectedfslib-prjstartvirtualizing")]
- public unsafe static extern HRESULT PrjStartVirtualizing ([In][Const] PWSTR virtualizationRootPath, [In][Const] PRJ_CALLBACKS* callbacks, [Optional][In][Const] void* instanceContext, [Optional][In][Const] PRJ_STARTVIRTUALIZING_OPTIONS* options, [Out] PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT* namespaceVirtualizationContext);
+ public unsafe static extern HRESULT PrjStartVirtualizing ([In][Const] PWSTR virtualizationRootPath, [In][Const] PRJ_CALLBACKS* callbacks, [Optional][In][Const] void* instanceContext, [Optional][In][Const] PRJ_STARTVIRTUALIZING_OPTIONS* options, [Out][RAIIFree ("PrjStopVirtualizing")] PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT* namespaceVirtualizationContext);
[DllImport ("PROJECTEDFSLIB.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows10.0.17763")]
@@ -626809,7 +626813,7 @@ public static class Apis
[DllImport ("Amsi.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows10.0.10240")]
[Documentation ("https://learn.microsoft.com/windows/win32/api/amsi/nf-amsi-amsiinitialize")]
- public unsafe static extern HRESULT AmsiInitialize ([In][Const] PWSTR appName, [Out] HAMSICONTEXT* amsiContext);
+ public unsafe static extern HRESULT AmsiInitialize ([In][Const] PWSTR appName, [Out][RAIIFree ("AmsiUninitialize")] HAMSICONTEXT* amsiContext);
[DllImport ("Amsi.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows10.0.10240")]
@@ -793544,7 +793548,7 @@ public static class Apis
[DllImport ("SecHost.dll", ExactSpelling = true, PreserveSig = false)]
[Documentation ("https://learn.microsoft.com/windows/win32/Services/subscribeservicechangenotifications")]
- public unsafe static extern uint SubscribeServiceChangeNotifications ([In] SC_HANDLE hService, [In] SC_EVENT_TYPE eEventType, [In] PSC_NOTIFICATION_CALLBACK pCallback, [Optional][In] void* pCallbackContext, [Out] PSC_NOTIFICATION_REGISTRATION* pSubscription);
+ public unsafe static extern uint SubscribeServiceChangeNotifications ([In] SC_HANDLE hService, [In] SC_EVENT_TYPE eEventType, [In] PSC_NOTIFICATION_CALLBACK pCallback, [Optional][In] void* pCallbackContext, [Out][RAIIFree ("UnsubscribeServiceChangeNotifications")] PSC_NOTIFICATION_REGISTRATION* pSubscription);
[DllImport ("SecHost.dll", ExactSpelling = true, PreserveSig = false)]
[Documentation ("https://learn.microsoft.com/windows/win32/Services/unsubscribeservicechangenotifications")]
@@ -793741,6 +793745,7 @@ using Windows.Win32.Foundation.Metadata;
namespace Windows.Win32.System.Services;
+[InvalidHandleValue (0L)]
[NativeTypedef]
public struct PSC_NOTIFICATION_REGISTRATION
{
@@ -820004,7 +820009,7 @@ public static class Apis
[DllImport ("api-ms-win-core-winrt-l1-1-0.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows8.0")]
[Documentation ("https://learn.microsoft.com/windows/win32/api/roapi/nf-roapi-roregisteractivationfactories")]
- public unsafe static extern HRESULT RoRegisterActivationFactories ([In][NativeArrayInfo (CountParamIndex = 2)] HSTRING* activatableClassIds, [In][NativeArrayInfo (CountParamIndex = 2)] PFNGETACTIVATIONFACTORY* activationFactoryCallbacks, [In] uint count, [Out] RO_REGISTRATION_COOKIE* cookie);
+ public unsafe static extern HRESULT RoRegisterActivationFactories ([In][NativeArrayInfo (CountParamIndex = 2)] HSTRING* activatableClassIds, [In][NativeArrayInfo (CountParamIndex = 2)] PFNGETACTIVATIONFACTORY* activationFactoryCallbacks, [In] uint count, [Out][RAIIFree ("RoRevokeActivationFactories")] RO_REGISTRATION_COOKIE* cookie);
[DllImport ("api-ms-win-core-winrt-l1-1-0.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows8.0")]
@@ -820019,7 +820024,7 @@ public static class Apis
[DllImport ("api-ms-win-core-winrt-l1-1-0.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows8.0")]
[Documentation ("https://learn.microsoft.com/windows/win32/api/roapi/nf-roapi-roregisterforapartmentshutdown")]
- public unsafe static extern HRESULT RoRegisterForApartmentShutdown ([In] IApartmentShutdown callbackObject, [Out] ulong* apartmentIdentifier, [Out] APARTMENT_SHUTDOWN_REGISTRATION_COOKIE* regCookie);
+ public unsafe static extern HRESULT RoRegisterForApartmentShutdown ([In] IApartmentShutdown callbackObject, [Out] ulong* apartmentIdentifier, [Out][RAIIFree ("RoUnregisterForApartmentShutdown")] APARTMENT_SHUTDOWN_REGISTRATION_COOKIE* regCookie);
[DllImport ("api-ms-win-core-winrt-l1-1-0.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows8.0")]
@@ -824657,6 +824662,7 @@ using Windows.Win32.Foundation.Metadata;
namespace Windows.Win32.System.WinRT;
+[InvalidHandleValue (0L)]
[NativeTypedef]
[Documentation ("https://learn.microsoft.com/windows/win32/WinRT/ro-registration-cookie")]
public struct RO_REGISTRATION_COOKIE
@@ -893548,14 +893554,14 @@ public static class Apis
[DllImport ("api-ms-win-core-psm-appnotify-l1-1-0.dll", ExactSpelling = true, PreserveSig = false)]
[Documentation ("https://learn.microsoft.com/windows/win32/api/appnotify/nf-appnotify-registerappstatechangenotification")]
- public unsafe static extern uint RegisterAppStateChangeNotification ([In] PAPPSTATE_CHANGE_ROUTINE Routine, [Optional][In] void* Context, [Out] PAPPSTATE_REGISTRATION* Registration);
+ public unsafe static extern uint RegisterAppStateChangeNotification ([In] PAPPSTATE_CHANGE_ROUTINE Routine, [Optional][In] void* Context, [Out][RAIIFree ("UnregisterAppStateChangeNotification")] PAPPSTATE_REGISTRATION* Registration);
[DllImport ("api-ms-win-core-psm-appnotify-l1-1-0.dll", ExactSpelling = true, PreserveSig = false)]
[Documentation ("https://learn.microsoft.com/windows/win32/api/appnotify/nf-appnotify-unregisterappstatechangenotification")]
public static extern void UnregisterAppStateChangeNotification ([In] PAPPSTATE_REGISTRATION Registration);
[DllImport ("api-ms-win-core-psm-appnotify-l1-1-1.dll", ExactSpelling = true, PreserveSig = false)]
- public unsafe static extern uint RegisterAppConstrainedChangeNotification ([In] PAPPCONSTRAIN_CHANGE_ROUTINE Routine, [Optional][In] void* Context, [Out] PAPPCONSTRAIN_REGISTRATION* Registration);
+ public unsafe static extern uint RegisterAppConstrainedChangeNotification ([In] PAPPCONSTRAIN_CHANGE_ROUTINE Routine, [Optional][In] void* Context, [Out][RAIIFree ("UnregisterAppConstrainedChangeNotification")] PAPPCONSTRAIN_REGISTRATION* Registration);
[DllImport ("api-ms-win-core-psm-appnotify-l1-1-1.dll", ExactSpelling = true, PreserveSig = false)]
public static extern void UnregisterAppConstrainedChangeNotification ([In] PAPPCONSTRAIN_REGISTRATION Registration);
@@ -908802,6 +908808,7 @@ using Windows.Win32.Foundation.Metadata;
namespace Windows.Win32.UI.Shell;
+[InvalidHandleValue (0L)]
[NativeTypedef]
public struct PAPPCONSTRAIN_REGISTRATION
{
@@ -908822,6 +908829,7 @@ using Windows.Win32.Foundation.Metadata;
namespace Windows.Win32.UI.Shell;
+[InvalidHandleValue (0L)]
[NativeTypedef]
public struct PAPPSTATE_REGISTRATION
{
|
Jevan Saks (jevansaks)
enabled auto-merge (squash)
October 19, 2026 00:08
Sergio Pedri (Sergio0694)
approved these changes
Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2375
Adds
RAIIFreeto 25 producer out-parameters so projections can wrap each returned handle in an owning type. AddsInvalidHandleValue(0)to the 8 handle typedefs that had no invalid value.The annotations go on the producers. A typedef such as
PHIDP_PREPARSED_DATAalso describes caller-allocated buffers, such as the oneGetRawInputDeviceInfo(RIDI_PREPARSEDDATA)fills, andHidD_FreePreparsedDatamust not free those. The typedefs carry noRAIIFree, and theHidP_*functions that consume the handle keep plain parameters.A projection needs an invalid value to tell an empty owner from a live one. The 7 typedefs that already had
-1, 0are unchanged.PHIDP_PREPARSED_DATAHidD_GetPreparsedData(PreparsedData)HidD_FreePreparsedData0HDEVQUERYDevCreateObjectQuery,DevCreateObjectQueryEx,DevCreateObjectQueryFromId,DevCreateObjectQueryFromIdEx,DevCreateObjectQueryFromIds,DevCreateObjectQueryFromIdsEx(phDevQuery)DevCloseObjectQuery0HAMSICONTEXTAmsiInitialize(amsiContext)AmsiUninitialize-1, 0NCRYPT_DESCRIPTOR_HANDLENCryptCreateProtectionDescriptor(phDescriptor)NCryptCloseProtectionDescriptor-1, 0NCRYPT_STREAM_HANDLENCryptStreamOpenToProtect,NCryptStreamOpenToUnprotect,NCryptStreamOpenToUnprotectEx(phStream)NCryptStreamClose-1, 0SAFER_LEVEL_HANDLESaferCreateLevel,SaferIdentifyLevel(pLevelHandle)SaferCloseLevel-1, 0PACKAGE_VIRTUALIZATION_CONTEXT_HANDLECreatePackageVirtualizationContext(context),DuplicatePackageVirtualizationContext(destContext)ReleasePackageVirtualizationContext0PACKAGEDEPENDENCY_CONTEXTAddPackageDependency,AddPackageDependency2(packageDependencyContext)RemovePackageDependency0PRJ_NAMESPACE_VIRTUALIZATION_CONTEXTPrjStartVirtualizing(namespaceVirtualizationContext)PrjStopVirtualizing-1, 0HTTP_PUSH_WAIT_HANDLEHttpPushEnable(phWait)HttpPushClose-1, 0PSC_NOTIFICATION_REGISTRATIONSubscribeServiceChangeNotifications(pSubscription)UnsubscribeServiceChangeNotifications0PAPPSTATE_REGISTRATIONRegisterAppStateChangeNotification(Registration)UnregisterAppStateChangeNotification0PAPPCONSTRAIN_REGISTRATIONRegisterAppConstrainedChangeNotification(Registration)UnregisterAppConstrainedChangeNotification0RO_REGISTRATION_COOKIERoRegisterActivationFactories(cookie)RoRevokeActivationFactories0APARTMENT_SHUTDOWN_REGISTRATION_COOKIERoRegisterForApartmentShutdown(regCookie)RoUnregisterForApartmentShutdown-1, 0The handles in the "Left out" section of #2375 are unchanged.
CsWin32
HidD_FreePreparsedDatareturnsBOOLEAN. CsWin32 needs support forBOOLEANcleanup results before it generates aSafeHandlefor the HID pair. That support is in microsoft/CsWin32#1859.Validation
scripts/DoTests.ps1after a full scrape and emit for x86, x64, and arm64: MetadataUtils.Tests 17/17, Win32MetadataScraperTests 50/50, Windows.Win32.Tests 13/13. The local build ran on an ARM64 host, so its scraper used-target x86_64-pc-windows-msvcto match the target that the x64 CI hosts use.RAIIFreewith the expected cleanup function on all 25 parameters andInvalidHandleValue(0)on all 8 typedefs.ContainsInteriorPointerschanges from Annotate 77 more caller-owned buffers containing interior pointers #2356.ReleaseHandlecalls the cleanup function,IsInvalidtreats 0 as invalid, and every producer has an overload with anoutowner parameter. With the 71.0.30-preview winmd, all 15 of these checks fail.HidP_GetCapssucceeded through bothDangerousValueandLease()on 32 of 33 interfaces, andReleaseHandlereturned true. Over 20,000 get-and-dispose cycles, private bytes grew 996 KB. The same loop without a free grew 9,520 KB.