internal static IEnumerable <string> EnumerateEnumerators()
        {
            List <string> ret     = new List <string>();
            StringBuilder builder = new StringBuilder(DeviceNativeMethods.MAX_DEVICE_ID_LEN);
            int           index   = 0;
            int           length  = DeviceNativeMethods.MAX_DEVICE_ID_LEN;
            CrError       result  = DeviceNativeMethods.CM_Enumerate_EnumeratorsW(index++, builder, ref length, 0);

            while (result != CrError.NO_SUCH_VALUE)
            {
                if (result != CrError.SUCCESS)
                {
                    break;
                }
                builder.Length = length;
                ret.Add(builder.ToString().Trim('\0'));
                length = DeviceNativeMethods.MAX_DEVICE_ID_LEN;
                result = DeviceNativeMethods.CM_Enumerate_EnumeratorsW(index++, builder, ref length, 0);
            }
            return(ret);
        }
 private static NtStatus ToNtStatus(this CrError error)
 {
     return(DeviceNativeMethods.CM_MapCrToWin32Err(error, Win32Error.ERROR_INVALID_PARAMETER).MapDosErrorToStatus());
 }