Esempio n. 1
0
        public void Read <T>(long position, out T structure) where T : struct
        {
            IntPtr dest = Marshal.AllocHGlobal(Marshal.SizeOf(default(T)));

            Win32APIs.memcpy(dest, new IntPtr(baseAccessor.ToInt64() + position), (int)Marshal.SizeOf(default(T)));
            structure = (T)Marshal.PtrToStructure(dest, typeof(T));
        }
Esempio n. 2
0
 public void Dispose()
 {
     if (baseAccessor != IntPtr.Zero)
     {
         Win32APIs.CloseHandle(baseAccessor);
     }
 }
Esempio n. 3
0
        public MemoryMappedViewAccessor(IntPtr baseMap)
        {
            this.baseMap = baseMap;
            baseAccessor = Win32APIs.MapViewOfFile(this.baseMap, MemoryMappedFileRights.ReadWrite, 0, 0, 0);

            //int* a = (int*)Win32APIs.MapViewOfFile(this.baseMap, MemoryMappedFileRights.Read, 0, 0, 0);
        }
Esempio n. 4
0
 public void Dispose()
 {
     if (basemap != IntPtr.Zero)
     {
         Win32APIs.UnmapViewOfFile(basemap);
     }
 }
        //받기 위한 연결시작
        public void Start()
        {
            this.handle =
                Win32APIs.CreateFile(
                    this.pipeName,
                    GENERIC_READ,
                    0,
                    IntPtr.Zero,
                    OPEN_EXISTING,
                    FILE_FLAG_OVERLAPPED,
                    IntPtr.Zero);

            //서버가 동작을 안하고있음
            if (this.handle.IsInvalid)
            {
                if (Error != null)
                {
                    nuiApp.Queue_Event(Error);
                }
                return;
            }

            this.stream = new FileStream(this.handle, FileAccess.Read, BUFFER_SIZE, true);

            WaitForData();
        }
Esempio n. 6
0
        public void Write <T>(long position, ref T structure) where T : struct
        {
            IntPtr structurePtr = Marshal.AllocHGlobal(Marshal.SizeOf(structure));

            Marshal.StructureToPtr(structure, structurePtr, false);
            Win32APIs.memcpy(new IntPtr(baseAccessor.ToInt64() + position), structurePtr, (int)Marshal.SizeOf(default(T)));
            Marshal.FreeHGlobal(structurePtr);
        }
Esempio n. 7
0
        public static MemoryMappedFile OpenExisting(string mappedName, MemoryMappedFileRights desiredAccessRights = MemoryMappedFileRights.ReadWrite)
        {
            MemoryMappedFile mappedFile = new MemoryMappedFile();

            //mappedFile.map = Win32APIs.OpenFileMapping(desiredAccessRights, false, @"Global\" + mappedName);
            mappedFile.rights  = desiredAccessRights;
            mappedFile.basemap = Win32APIs.OpenFileMapping(mappedFile.rights, false, mappedName);

            if (mappedFile.basemap == IntPtr.Zero) //생성 실패
            {
                return(null);
            }

            return(mappedFile);
        }