Exemple #1
0
 public void Update()
 {
     WinApiImport.QueryPerformanceCounter(out PerfomanceCount);
     WinApiImport.QueryPerformanceFrequency(out Frequency);
     WinApiImport.GetSystemTimeAsFileTime(out var fileTime);
     SystemFileAsFileTime = ((ulong)fileTime.dwLowDateTime << 32) + (ulong)fileTime.dwHighDateTime;
 }
Exemple #2
0
        public static string Read(string name)
        {
            var hEvent = WinApiImport.CreateEvent(new LPSECURITY_ATTRIBUTES(), false, false, name);

            if (hEvent == IntPtr.Zero)
            {
                return(string.Empty);
            }

            var ov = new OVERLAPPED {
                hEvent = hEvent
            };
            var info = WinApiImport.GetMailslotInfo(slots[name], 0, out var size, out var _, 0);

            if (info == IntPtr.Zero || size <= 0)
            {
                return(string.Empty);
            }

            var msgPointer = Marshal.AllocHGlobal(size);
            var res        = WinApiImport.ReadFile(slots[name], msgPointer, size, out var read, ref ov);

            if (res == IntPtr.Zero)
            {
                return(string.Empty);
            }

            var message = Marshal.PtrToStringAnsi(msgPointer);

            return(message);
        }
Exemple #3
0
        public static void Close(string name)
        {
            var slot = slots[name];

            WinApiImport.CloseHandle(slot);
            slots.Remove(name);
            files.Remove(name);
        }
Exemple #4
0
        public static void Wait(IntPtr semaphore)
        {
#if DEBUG
            return;
#endif

            while (WinApiImport.WaitForSingleObject(semaphore, int.MaxValue) != 0)
            {
            }
        }
Exemple #5
0
        public static IntPtr Create(string name, int limit)
        {
#if DEBUG
            return(IntPtr.Zero);
#endif

            var options   = new LPSECURITY_ATTRIBUTES();
            var semaphore = WinApiImport.CreateSemaphore(ref options, limit, limit, name);

            return(semaphore);
        }
Exemple #6
0
        public static bool Create(string name)
        {
            var slot = WinApiImport.CreateMailslot(SlotPrefix + name, 0, int.MaxValue, new LPSECURITY_ATTRIBUTES());

            if (slot == invalidHandle)
            {
                return(false);
            }

            slots[name] = slot;
            return(true);
        }
Exemple #7
0
        public static bool Write(string name, string message)
        {
            var file = GetFile(name);

            if (file == invalidHandle)
            {
                return(false);
            }

            var size = (message.Length + 1) * sizeof(char);
            var res  = WinApiImport.WriteFile(file, message, size, out var written, new OVERLAPPED());

            if (res == IntPtr.Zero)
            {
                return(false);
            }
            return(true);
        }
Exemple #8
0
        private static IntPtr GetFile(string name)
        {
            if (files.ContainsKey(name))
            {
                return(files[name]);
            }

            var file = WinApiImport.CreateFile(
                SlotPrefix + name,
                WinApiImport.GenericWriteAccess,
                WinApiImport.FileShareRead,
                new LPSECURITY_ATTRIBUTES(),
                (int)FileMode.Open,
                WinApiImport.FileAttributeNormal,
                IntPtr.Zero);

            if (file != invalidHandle)
            {
                files[name] = file;
            }

            return(file);
        }
Exemple #9
0
        public static void Release(IntPtr semaphore)
        {
#if !DEBUG
            WinApiImport.ReleaseSemaphore(semaphore, 1, IntPtr.Zero);
#endif
        }
Exemple #10
0
        public static void Close(IntPtr semaphore)
        {
#if !DEBUG
            WinApiImport.CloseHandle(semaphore);
#endif
        }