Interop.OpenFileMapping C# (CSharp) Method

OpenFileMapping() public static method

public static OpenFileMapping ( int desiredAccess, bool inheritHandle, string name ) : SafeMemoryMappedFileHandle
desiredAccess int
inheritHandle bool
name string
return SafeMemoryMappedFileHandle
    public static SafeMemoryMappedFileHandle OpenFileMapping(
            int desiredAccess,
            bool inheritHandle,
            string name)
    {
        return Interop.Kernel32.OpenFileMappingFromApp(desiredAccess, inheritHandle, name);
    }
    public static IntPtr VirtualAlloc(

Usage Example

Beispiel #1
0
        /// <summary>
        /// Used by the OpenExisting factory method group and by CreateOrOpen if access is write.
        /// We'll throw an ArgumentException if the file mapping object didn't exist and the
        /// caller used CreateOrOpen since Create isn't valid with Write access
        /// </summary>
        private static SafeMemoryMappedFileHandle OpenCore(
            string mapName, HandleInheritability inheritability, int desiredAccessRights, bool createOrOpen)
        {
            SafeMemoryMappedFileHandle handle = Interop.OpenFileMapping(
                desiredAccessRights, (inheritability & HandleInheritability.Inheritable) != 0, mapName);
            int lastError = Marshal.GetLastWin32Error();

            if (handle.IsInvalid)
            {
                handle.Dispose();
                if (createOrOpen && (lastError == Interop.Errors.ERROR_FILE_NOT_FOUND))
                {
                    throw new ArgumentException(SR.Argument_NewMMFWriteAccessNotAllowed, "access");
                }
                else
                {
                    throw Win32Marshal.GetExceptionForWin32Error(lastError);
                }
            }
            return(handle);
        }
All Usage Examples Of Interop::OpenFileMapping