// Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. namespace Microsoft.VisualStudio.Threading { using System; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; /// /// P/Invoke methods. /// internal static partial class NativeMethods { /// /// Indicates that the lifetime of the registration must not be tied to the lifetime of the thread issuing the RegNotifyChangeKeyValue call. /// Note: This flag value is only supported in Windows 8 and later. /// internal const RegistryChangeNotificationFilters REG_NOTIFY_THREAD_AGNOSTIC = (RegistryChangeNotificationFilters)0x10000000L; /// /// Really truly non pumping wait. /// Raw IntPtrs have to be used, because the marshaller does not support arrays of SafeHandle, only /// single SafeHandles. /// /// The number of handles in the array. /// The handles to wait for. /// A flag indicating whether all handles must be signaled before returning. /// A timeout that will cause this method to return. [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] internal static extern int WaitForMultipleObjects(uint handleCount, IntPtr[] waitHandles, [MarshalAs(UnmanagedType.Bool)] bool waitAll, uint millisecondsTimeout); /// /// Registers to receive notification of changes to a registry key. /// /// The handle to the registry key to watch. /// true to watch the keys descendent keys as well; false to watch only this key without descendents. /// The types of changes to watch for. /// A handle to the event to set when a change occurs. /// If this parameter is TRUE, the function returns immediately and reports changes by signaling the specified event. If this parameter is FALSE, the function does not return until a change has occurred. /// A win32 error code. ERROR_SUCCESS (0) if successful. [DllImport("Advapi32.dll", ExactSpelling = true, SetLastError = true)] internal static extern int RegNotifyChangeKeyValue( SafeRegistryHandle hKey, [MarshalAs(UnmanagedType.Bool)] bool watchSubtree, RegistryChangeNotificationFilters notifyFilter, SafeWaitHandle hEvent, [MarshalAs(UnmanagedType.Bool)] bool asynchronous); } }