예제 #1
0
        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();
            }
        }
예제 #2
0
 public static extern SafeFileHandle CreateFileMapping(
     SafeFileHandle hFile,
     IntPtr lpFileMappingAttributes,
     FileMapProtection flProtect,
     uint dwMaximumSizeHigh,
     uint dwMaximumSizeLow,
     [MarshalAs(UnmanagedType.LPTStr)] string lpName);
예제 #3
0
 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);
 }
예제 #4
0
 internal static extern SharedMemorySafeHandle CreateFileMapping(
     IntPtr fileHandle,
     ref SECURITY_ATTRIBUTES fileMappingAttributes,
     FileMapProtection fileMapProtect,
     uint maximumSizeHigh,
     uint maximumSizeLow,
     string name);
예제 #5
0
 public static extern IntPtr CreateFileMapping(
     IntPtr hFile,
     IntPtr lpFileMappingAttributes,
     FileMapProtection flProtect,
     uint dwMaximumSizeHigh,
     uint dwMaximumSizeLow,
     [MarshalAs(UnmanagedType.LPStr)] string lpName);
예제 #6
0
 internal static extern IntPtr CreateFileMapping(
     IntPtr hFile,
     ref SecurityAttributes lpAttributes,
     FileMapProtection flProtect,
     Int32 dwMaxSizeHi,
     Int32 dwMaxSizeLow,
     string lpName);
예제 #7
0
 public static extern IntPtr CreateFileMapping(
     IntPtr hFile,
     IntPtr lpFileMappingAttributes,
     FileMapProtection flProtect,
     uint dwMaximumSizeHigh,
     uint dwMaximumSizeLow,
     string lpName);
예제 #8
0
 private static extern IntPtr CreateFileMapping(
     IntPtr hFile,
     IntPtr lpFileMappingAttributes,
     FileMapProtection flProtect,
     uint dwMaximumSizeHigh,
     uint dwMaximumSizeLow,
     [MarshalAs(UnmanagedType.LPStr)] string lpName);
예제 #9
0
        /// <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);
            }
        }
예제 #10
0
 public static extern SafeFileHandle CreateFileMapping(
     SafeFileHandle hFile,
     IntPtr lpFileMappingAttributes,
     FileMapProtection flProtect,
     uint dwMaximumSizeHigh,
     uint dwMaximumSizeLow,
     IntPtr lpName
     );
예제 #11
0
 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
     );
예제 #12
0
        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;
        }
예제 #13
0
 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)));
 }
예제 #14
0
        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);
            }
        }
예제 #15
0
 internal static extern IntPtr CreateFileMapping(IntPtr hFile,
     int lpAttributes,
     FileMapProtection flProtect,
     uint dwMaximumSizeHigh,
     uint dwMaximumSizeLow,
     string lpName);
예제 #16
0
 public SharedMemoryIPC(string name, uint size, FileMapProtection fileMapProtection, string serverEventName, string clientEventName)
 {
     initializeKernelObjects(name, size, fileMapProtection, serverEventName, clientEventName);
     role = SERVER;
 }
예제 #17
0
 public static extern IntPtr CreateFileMapping(
        IntPtr hFile,
        ref SECURITY_ATTRIBUTES attributes,
        FileMapProtection flProtect,
        uint dwMaximumSizeHigh,
        uint dwMaximumSizeLow,
        string lpName);
예제 #18
0
파일: Program.cs 프로젝트: wookly/SemiLink
 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);
 }
예제 #19
0
        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));
        }
예제 #20
0
 internal static extern SafeFileMappingHandle CreateFileMapping(SafeFileHandle handle, IntPtr attributes, FileMapProtection protect, uint maximumSizeHigh, uint maximumSizeLow, string name);
예제 #21
0
 static extern IntPtr CreateFile(string fileName, uint fileAccess, uint fileShare, FileMapProtection securityAttributes, uint creationDisposition, uint flags, IntPtr overlapped);
예제 #22
0
 public static extern SafeFileHandle CreateFileMapping(SafeFileHandle hFile, IntPtr lpAttributes, FileMapProtection fProtect, int dwMaximumSizeHigh, int dwMaximumSizeLow, string lpName);
예제 #23
0
 private static extern IntPtr CreateFileMapping(IntPtr hFile, IntPtr lpAttributes, FileMapProtection flProtect, Int32 dwMaxSizeHi, Int32 dwMaxSizeLow, string lpName);
예제 #24
0
 private static extern IntPtr CreateFileMapping(IntPtr hFile, IntPtr lpAttributes, FileMapProtection flProtect, Int32 dwMaxSizeHi, Int32 dwMaxSizeLow, string lpName);
예제 #25
0
 internal static extern SafeMemoryMappedFileHandle CreateFileMapping(SafeFileHandle hFile, IntPtr lpAttributes, FileMapProtection fProtect, int dwMaxSizeHi, int dwMaxSizeLo, string lpName);
예제 #26
0
 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);
예제 #28
0
 /// <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)
 {
 }
예제 #29
0
 internal static extern SafeMemoryMappedFileHandle CreateFileMapping(SafeFileHandle hFile, IntPtr lpAttributes, FileMapProtection fProtect, int dwMaxSizeHi, int dwMaxSizeLo, string lpName);
예제 #30
0
 public static extern MemoryMappedHandle CreateFileMapping(SafeHandle hFile, IntPtr lpFileMappingAttributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, [MarshalAs(UnmanagedType.LPTStr)] string lpName);
예제 #31
0
		public static extern SafeMemoryMappedFileHandle CreateFileMapping(SafeFileHandle hFile, SECURITY_ATTRIBUTES lpAttributes, FileMapProtection fProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);