Пример #1
0
 public static extern int WriteFile(IntPtr hFile, IntPtr lpBuffer, int nNumberOfBytesToWrite,
     ref int lpNumberOfBytesWritten, ref OVERLAPPED lpOverlapped);
Пример #2
0
 public static extern int WriteFileEx(IntPtr hFile, IntPtr lpBuffer, int nNumberOfBytesToWrite,
     ref OVERLAPPED lpOverlapped, ref int lpCompletionRoutine);
Пример #3
0
 public static extern int UnlockFileEx(IntPtr hFile, int dwReserved, int nNumberOfBytesToUnlockLow,
     int nNumberOfBytesToUnlockHigh, ref OVERLAPPED lpOverlapped);
Пример #4
0
 public static extern int WaitCommEvent(IntPtr hFile, ref int lpEvtMask, ref OVERLAPPED lpOverlapped);
Пример #5
0
 public static extern int TransactNamedPipe(IntPtr hNamedPipe, IntPtr lpInBuffer, int nInBufferSize,
     IntPtr lpOutBuffer, int nOutBufferSize, ref int lpBytesRead, ref OVERLAPPED lpOverlapped);
Пример #6
0
 public static extern int ReadFile(IntPtr hFile, IntPtr lpBuffer, int nNumberOfBytesToRead,
     ref int lpNumberOfBytesRead, ref OVERLAPPED lpOverlapped);
Пример #7
0
 public static extern int GetOverlappedResult(IntPtr hFile, ref OVERLAPPED lpOverlapped,
     ref int lpNumberOfBytesTransferred, int bWait);
Пример #8
0
 public static extern int ConnectNamedPipe(IntPtr hNamedPipe, ref OVERLAPPED lpOverlapped);
Пример #9
0
        public static unsafe DeviceInfo GetUSBDeviceInfo(string printerName)
        {
            string response = "";

            var deviceInfo = new DeviceInfo();
            try
            {
                var file = OpenUSBPrinter(printerName);

                var packet = new byte[2048];
                int size = 0;

                var buffer = new byte[255];
                fixed (byte* p = packet)
                {
                    var ptr = (IntPtr) p;

                    int result = Kernel.DeviceIoControl(file.DangerousGetHandle(), // device to be queried
                        IOCTL_USBPRINT_GET_1284_ID, // operation to perform
                        IntPtr.Zero, 0, // no input buffer
                        ptr, packet.Length, // output buffer
                        ref size, // # bytes returned
                        IntPtr.Zero); // synchronous I/O

                    if (size > 0)
                    {
                        deviceInfo.DeviceId = Encoding.ASCII.GetString(packet);
                    }

                    var overlapped = new OVERLAPPED();
                    result = Kernel.ReadFile(file.DangerousGetHandle(), ptr, packet.Length, ref size, ref overlapped);

                    if (size > 0)
                    {
                        deviceInfo.ExtData = Encoding.ASCII.GetString(packet);
                    }
                }

                Kernel.CloseHandle(file.DangerousGetHandle());
            }
            catch (Exception e)
            {
                Global.Logger.Fatal(e.Message);
            }
            return deviceInfo;
        }