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

TryMakeWin32ErrorCodeFromHR() static private méthode

Returns a Win32 error code for the specified HRESULT if it came from FACILITY_WIN32 If not, returns the HRESULT unchanged
static private TryMakeWin32ErrorCodeFromHR ( int hr ) : int
hr int
Résultat int
        internal static int TryMakeWin32ErrorCodeFromHR(int hr)
        {
            if ((0xFFFF0000 & hr) == 0x80070000)
            {
                // Win32 error, Win32Marshal.GetExceptionForWin32Error expects the Win32 format
                hr &= 0x0000FFFF;
            }

            return hr;
        }

Usage Example

Exemple #1
0
        public static SafeFileHandle CreateSafeFileHandle(
            this IStorageFolder rootDirectory,
            string relativePath,
            FileMode mode,
            FileAccess access,
            FileShare share     = FileShare.Read,
            FileOptions options = FileOptions.None)
        {
            if (rootDirectory == null)
            {
                throw new ArgumentNullException(nameof(rootDirectory));
            }
            if (relativePath == null)
            {
                throw new ArgumentNullException(nameof(relativePath));
            }

            HANDLE_CREATION_OPTIONS creationOptions = FileModeToCreationOptions(mode);
            HANDLE_ACCESS_OPTIONS   accessOptions   = FileAccessToHandleAccessOptions(access);
            HANDLE_SHARING_OPTIONS  sharingOptions  = FileShareToHandleSharingOptions(share);
            HANDLE_OPTIONS          handleOptions   = FileOptionsToHandleOptions(options);

            IStorageFolderHandleAccess handleAccess = ((object)rootDirectory) as IStorageFolderHandleAccess;

            if (handleAccess == null)
            {
                return(null);
            }

            SafeFileHandle handle;

            int result = handleAccess.Create(
                relativePath,
                creationOptions,
                accessOptions,
                sharingOptions,
                handleOptions,
                IntPtr.Zero,
                out handle);

            if (result != 0)
            {
                throw Win32Marshal.GetExceptionForWin32Error(Win32Marshal.TryMakeWin32ErrorCodeFromHR(result), relativePath);
            }

            return(handle);
        }
All Usage Examples Of System.IO.Win32Marshal::TryMakeWin32ErrorCodeFromHR