System.IO.Win32Marshal.GetExceptionForLastWin32Error C# (CSharp) Méthode

GetExceptionForLastWin32Error() static private méthode

Converts, resetting it, the last Win32 error into a corresponding Exception object.
static private GetExceptionForLastWin32Error ( ) : Exception
Résultat System.Exception
        internal static Exception GetExceptionForLastWin32Error()
        {
            int errorCode = Marshal.GetLastWin32Error();
            return GetExceptionForWin32Error(errorCode, String.Empty);
        }

Same methods

Win32Marshal::GetExceptionForLastWin32Error ( string path ) : Exception

Usage Example

Exemple #1
0
        public static string[] GetLogicalDrives()
        {
            int drives = Interop.Kernel32.GetLogicalDrives();

            if (drives == 0)
            {
                throw Win32Marshal.GetExceptionForLastWin32Error();
            }

            // GetLogicalDrives returns a bitmask starting from
            // position 0 "A" indicating whether a drive is present.
            // Loop over each bit, creating a string for each one
            // that is set.

            uint d     = (uint)drives;
            int  count = 0;

            while (d != 0)
            {
                if (((int)d & 1) != 0)
                {
                    count++;
                }
                d >>= 1;
            }

            string[]    result = new string[count];
            Span <char> root   = stackalloc char[] { 'A', ':', '\\' };

            d     = (uint)drives;
            count = 0;
            while (d != 0)
            {
                if (((int)d & 1) != 0)
                {
                    result[count++] = root.ToString();
                }
                d >>= 1;
                root[0]++;
            }
            return(result);
        }
    }
All Usage Examples Of System.IO.Win32Marshal::GetExceptionForLastWin32Error