public static SharedMemory Create(string name, uint initialSize, FileMapProtection protection) { IntPtr fmHandle = CreateFileMapping(invalidHandleValue, IntPtr.Zero, protection, 0, initialSize, name); if (Marshal.GetLastWin32Error() == 183) { throw new ObjectAlreadyExistException(name); } if (fmHandle == IntPtr.Zero) { throw new Win32Exception(); } IntPtr Base = MapViewOfFile(fmHandle, FileMapAccess.FileMapReadWrite, 0, 0, 0); if (Base != IntPtr.Zero) { return(new SharedMemory(fmHandle, Base, initialSize)); } else { throw new Win32Exception(); } }
public static extern SafeFileHandle CreateFileMapping( SafeFileHandle hFile, IntPtr lpFileMappingAttributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, [MarshalAs(UnmanagedType.LPTStr)] string lpName);
public static IntPtr CreateFileMapping(SafeFileHandle handle, FileMapProtection flProtect, long ddMaxSize, string lpName) { var Hi = (int) (ddMaxSize/int.MaxValue); var Lo = (int) (ddMaxSize%int.MaxValue); return CreateFileMapping(handle.DangerousGetHandle(), IntPtr.Zero, flProtect, Hi, Lo, lpName); }
internal static extern SharedMemorySafeHandle CreateFileMapping( IntPtr fileHandle, ref SECURITY_ATTRIBUTES fileMappingAttributes, FileMapProtection fileMapProtect, uint maximumSizeHigh, uint maximumSizeLow, string name);
public static extern IntPtr CreateFileMapping( IntPtr hFile, IntPtr lpFileMappingAttributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, [MarshalAs(UnmanagedType.LPStr)] string lpName);
internal static extern IntPtr CreateFileMapping( IntPtr hFile, ref SecurityAttributes lpAttributes, FileMapProtection flProtect, Int32 dwMaxSizeHi, Int32 dwMaxSizeLow, string lpName);
public static extern IntPtr CreateFileMapping( IntPtr hFile, IntPtr lpFileMappingAttributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
private static extern IntPtr CreateFileMapping( IntPtr hFile, IntPtr lpFileMappingAttributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, [MarshalAs(UnmanagedType.LPStr)] string lpName);
/// <summary> /// コンストラクタ 指定されたファイルを指定されたアクセスモードと共有モードで開く /// </summary> /// <param name="fileName">ファイル名</param> /// <param name="fileAccess">ファイルアクセスモード</param> /// <param name="fileShare">ファイル共有モード</param> public MemMapFile(string fileName, FileAccess fileAccess, FileShare fileShare) { EFileAccess efa; EFileShare efs; efa = 0; if ((fileAccess & FileAccess.Read) == FileAccess.Read) { efa |= EFileAccess.GenericRead; } if ((fileAccess & FileAccess.Write) == FileAccess.Write) { efa |= EFileAccess.GenericWrite; } efs = EFileShare.None; if ((fileShare & FileShare.Read) == FileShare.Read) { efs |= EFileShare.Read; } if ((fileShare & FileShare.Write) == FileShare.Write) { efs |= EFileShare.Write; } m_FileName = fileName; m_FileHandle = CreateFileW(fileName, efa, efs, IntPtr.Zero, ECreationDisposition.OpenExisting, EFileAttributes.Normal, IntPtr.Zero); if (m_FileHandle == INVALID_HANDLE_VALUE) { Dispose(); throw new MemMapFileException(Marshal.GetLastWin32Error(), fileName); } if (!GetFileSizeEx(m_FileHandle, out m_FileSize)) { Dispose(); throw new MemMapFileException(Marshal.GetLastWin32Error(), fileName); } m_FileMapProtection = 0; m_FileMapAccess = 0; if ((efa & EFileAccess.GenericRead) == EFileAccess.GenericRead) { m_FileMapProtection |= FileMapProtection.PageReadonly; m_FileMapAccess |= FileMapAccess.FileMapRead; } if ((efa & EFileAccess.GenericWrite) == EFileAccess.GenericWrite) { m_FileMapProtection = FileMapProtection.PageReadWrite; // 書き込み時は FileMapProtection.PageReadonly を消したいので代入してる m_FileMapAccess |= FileMapAccess.FileMapWrite; } m_MappingHandle = CreateFileMappingW(m_FileHandle, IntPtr.Zero, m_FileMapProtection, 0, 0, IntPtr.Zero); if (m_MappingHandle == IntPtr.Zero) { Dispose(); throw new MemMapFileException(Marshal.GetLastWin32Error(), fileName); } }
public static extern SafeFileHandle CreateFileMapping( SafeFileHandle hFile, IntPtr lpFileMappingAttributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, IntPtr lpName );
static extern IntPtr CreateFileMapping( IntPtr hFile, // LPCSTR lpFileName IntPtr lpFileMappingAttributes, // DWORD dwDesiredAccess FileMapProtection flProtect, // DWORD dwSharedMode uint dwMaximumSizeHigh, // LPSECURITY_ATTRIBUTES lpSecurityAttributes uint dwMaximumSizeLow, // DWORD dwCreationDisposition string lpName, // DWORD dwFladsAndAttributes IntPtr hTemplateFile // HANDLE hTemplateFile );
public SharedMemoryIPC(string name, uint size, FileMapProtection fileMapProtection) { string countInstance = Interlocked.Increment(ref _instanceCount).ToString(); string serverEventName = name + "." + "server" + countInstance; string clientEventName = name + "." + "client" + countInstance; initializeKernelObjects(name, size, fileMapProtection, serverEventName, clientEventName); WriteString(serverEventName, 0); WriteString(clientEventName, serverEventName.Length + 1); role = SERVER; }
internal static SafeMapHandle CreateFileMapping( FileStream fileStream, long fileSize, FileMapProtection protection) { return (ThrowOnError( CreateFileMapping( fileStream.SafeFileHandle, IntPtr.Zero, protection, (uint)((fileSize >> 32) & 0xFFFFFFFF), (uint)(fileSize & 0xFFFFFFFF), null))); }
void initializeKernelObjects(string name, uint size, FileMapProtection fileMapProtection, string serverEventName, string clientEventName) { bool newCreatedSrEvent; bool newCreatedClEvent; sharedMemory = Create(name, size, FileMapProtection.PageExecuteReadWrite); serverEvent = new EventWaitHandle(false, EventResetMode.ManualReset, serverEventName, out newCreatedSrEvent); if (newCreatedSrEvent != true) { throw new ObjectAlreadyExistException(serverEventName); } clientEvent = new EventWaitHandle(false, EventResetMode.ManualReset, clientEventName, out newCreatedClEvent); if (newCreatedClEvent != true) { throw new ObjectAlreadyExistException(clientEventName); } }
internal static extern IntPtr CreateFileMapping(IntPtr hFile, int lpAttributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
public SharedMemoryIPC(string name, uint size, FileMapProtection fileMapProtection, string serverEventName, string clientEventName) { initializeKernelObjects(name, size, fileMapProtection, serverEventName, clientEventName); role = SERVER; }
public static extern IntPtr CreateFileMapping( IntPtr hFile, ref SECURITY_ATTRIBUTES attributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
internal static IntPtr CreateFileMapping(System.IO.FileStream File, FileMapProtection flProtect, Int64 ddMaxSize, string lpName) { int Hi = (Int32)(ddMaxSize / Int32.MaxValue); int Lo = (Int32)(ddMaxSize % Int32.MaxValue); return CreateFileMapping(File.SafeFileHandle.DangerousGetHandle(), IntPtr.Zero, flProtect, Hi, Lo, lpName); }
internal static SafeMemoryMappedFileHandle CreateFileMapping(SafeFileHandle hFile, FileMapProtection flProtect, Int64 ddMaxSize, string lpName) { int hi = (Int32)(ddMaxSize / Int32.MaxValue); int lo = (Int32)(ddMaxSize % Int32.MaxValue); return(CreateFileMapping(hFile, IntPtr.Zero, flProtect, hi, lo, lpName)); }
internal static extern SafeFileMappingHandle CreateFileMapping(SafeFileHandle handle, IntPtr attributes, FileMapProtection protect, uint maximumSizeHigh, uint maximumSizeLow, string name);
static extern IntPtr CreateFile(string fileName, uint fileAccess, uint fileShare, FileMapProtection securityAttributes, uint creationDisposition, uint flags, IntPtr overlapped);
public static extern SafeFileHandle CreateFileMapping(SafeFileHandle hFile, IntPtr lpAttributes, FileMapProtection fProtect, int dwMaximumSizeHigh, int dwMaximumSizeLow, string lpName);
private static extern IntPtr CreateFileMapping(IntPtr hFile, IntPtr lpAttributes, FileMapProtection flProtect, Int32 dwMaxSizeHi, Int32 dwMaxSizeLow, string lpName);
internal static extern SafeMemoryMappedFileHandle CreateFileMapping(SafeFileHandle hFile, IntPtr lpAttributes, FileMapProtection fProtect, int dwMaxSizeHi, int dwMaxSizeLo, string lpName);
internal static SafeMemoryMappedFileHandle CreateFileMapping(SafeFileHandle hFile, FileMapProtection flProtect, Int64 ddMaxSize, string lpName) { int hi = (Int32)(ddMaxSize / Int32.MaxValue); int lo = (Int32)(ddMaxSize % Int32.MaxValue); return CreateFileMapping(hFile, IntPtr.Zero, flProtect, hi, lo, lpName); }
public static extern SafeMemoryMappedFileHandle CreateFileMapping(SafeFileHandle hFile, SECURITY_ATTRIBUTES lpAttributes, FileMapProtection fProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
/// <summary> /// To connect with this shared memory IPC server use hconnect method exclusively. SharedMemoryIPC object are /// created without named kernel object, thus is safer. /// </summary> /// <param name="sharedMemoryIPCName"></param> /// <returns></returns> public SharedMemoryIPC(uint size, FileMapProtection fileMapProtection, out Handles handles) { }
public static extern MemoryMappedHandle CreateFileMapping(SafeHandle hFile, IntPtr lpFileMappingAttributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, [MarshalAs(UnmanagedType.LPTStr)] string lpName);