Esempio n. 1
0
        public static IntPtr VirtualAlloc(int size)
        {
            IntPtr memoryHandle = VirtualAlloc(IntPtr.Zero, (UIntPtr)size, AllocationType.Commit, MemoryProtection.ReadWrite);

            if (memoryHandle == IntPtr.Zero)
            {
                int lastError = Marshal.GetLastWin32Error();
                Log.Error?.Out($"Не удалось выделить память: {lastError} {WinErrors.GetSystemMessage(lastError)}");
            }
            return(memoryHandle);
        }
Esempio n. 2
0
        public static IntPtr Open()
        {
            IntPtr handle = CreateFile("\\\\.\\fdraw0", EFileAccess.GenericRead | EFileAccess.GenericWrite, 0, IntPtr.Zero, ECreationDisposition.OpenExisting, 0, IntPtr.Zero);

            if ((int)handle == INVALID_HANDLE_VALUE)
            {
                int lastError = Marshal.GetLastWin32Error();
                Log.Error?.Out($"Не удалось открыть драйвер: {lastError} {WinErrors.GetSystemMessage(lastError)}");
                return(handle);
            }
            return(handle);
        }
Esempio n. 3
0
        public static unsafe IntPtr Open(DataRate dataRate, Drive drive)
        {
            string fileName = drive == Drive.A ? "\\\\.\\fdraw0" : "\\\\.\\fdraw1";
            IntPtr handle   = CreateFile(fileName, EFileAccess.GenericRead | EFileAccess.GenericWrite, 0, IntPtr.Zero, ECreationDisposition.OpenExisting, 0, IntPtr.Zero);

            if ((int)handle == INVALID_HANDLE_VALUE)
            {
                int lastError = Marshal.GetLastWin32Error();
                Log.Error?.Out($"Не удалось открыть драйвер: {lastError} {WinErrors.GetSystemMessage(lastError)} {(lastError == 2 ? $"(Drive {drive}: is not installed)" : "")}");
                return(handle);
            }
            uint dwRet;
            bool r = DeviceIoControl(handle, IOCTL_FD_SET_DATA_RATE, (IntPtr)(&dataRate), sizeof(byte), IntPtr.Zero, 0, out dwRet, IntPtr.Zero);

            if (!r)
            {
                int lastError = Marshal.GetLastWin32Error();
                Log.Error?.Out($"Ошибка при установке DataRate: {lastError} {WinErrors.GetSystemMessage(lastError)}");
            }
            return(handle);
        }