Beispiel #1
0
        protected virtual Point GetCoordinate(short linkCollection, Screen currentScr, IntPtr pRawDataPacket)
        {
            int physicalX = 0;
            int physicalY = 0;

            HidNativeApi.HidP_GetScaledUsageValue(HidReportType.Input, NativeMethods.GenericDesktopPage, linkCollection, NativeMethods.XCoordinateId, ref physicalX, _hPreparsedData.DangerousGetHandle(), pRawDataPacket, _dwSizHid);
            HidNativeApi.HidP_GetScaledUsageValue(HidReportType.Input, NativeMethods.GenericDesktopPage, linkCollection, NativeMethods.YCoordinateId, ref physicalY, _hPreparsedData.DangerousGetHandle(), pRawDataPacket, _dwSizHid);

            int x, y;

            if (_isAxisCorresponds)
            {
                x = physicalX * currentScr.Bounds.Width / _physicalMax.X;
                y = physicalY * currentScr.Bounds.Height / _physicalMax.Y;
            }
            else
            {
                x = physicalY * currentScr.Bounds.Width / _physicalMax.Y;
                y = physicalX * currentScr.Bounds.Height / _physicalMax.X;
            }
            x = _xAxisDirection ? x : currentScr.Bounds.Width - x;
            y = _yAxisDirection ? y : currentScr.Bounds.Height - y;

            return(new Point(x + currentScr.Bounds.X, y + currentScr.Bounds.Y));
        }
            internal static IEnumerable <string> EnumeratePorts()
            {
                uint needed   = 0;
                uint returned = 0;

                // As per MSDN, call EnumPorts with an empty buffer.
                // This call will fail, but will populate 'needed' with the required size of the buffer.
                using (SafeUnmanagedMemoryHandle nullBuffer = new SafeUnmanagedMemoryHandle(0))
                {
                    EnumPorts(null, 2, nullBuffer, 0, ref needed, ref returned);
                }

                // Allocate the required memory and retrieve the port data
                using (SafeUnmanagedMemoryHandle buffer = new SafeUnmanagedMemoryHandle((int)needed))
                {
                    if (EnumPorts(null, 2, buffer, needed, ref needed, ref returned))
                    {
                        PortInfo[] ports       = new PortInfo[returned];
                        IntPtr     currentPort = buffer.DangerousGetHandle();
                        for (int i = 0; i < returned; i++)
                        {
                            ports[i]    = Marshal.PtrToStructure <PortInfo>(currentPort);
                            currentPort = IntPtr.Add(currentPort, Marshal.SizeOf <PortInfo>());
                        }
                        return(ports.Select(n => n.PortName));
                    }
                    else
                    {
                        throw new Win32Exception();
                    }
                }
            }
            internal static void XcvPortData(SafePrinterHandle xcvMonitor, string command, object portData)
            {
                // TCPMON XCV commands are listed at https://msdn.microsoft.com/en-us/windows/hardware/drivers/print/tcpmon-xcv-commands
                int size = Marshal.SizeOf(portData);

                using (SafeUnmanagedMemoryHandle inputDataPointer = new SafeUnmanagedMemoryHandle(size))
                {
                    Marshal.StructureToPtr(portData, inputDataPointer.DangerousGetHandle(), true);
                    if (!XcvData(xcvMonitor, command, inputDataPointer, (uint)size, IntPtr.Zero, 0, out uint outputNeededSize, out uint status))
                    {
                        throw new Win32Exception();
                    }
                }
            }