Exemplo n.º 1
0
            /// <summary>
            /// Changes the properties of a device by calling the <see cref="SetupDiSetClassInstallParams"/> and <see cref="SetupDiChangeState"/> functions
            /// </summary>
            /// <param name="installFunction">The function to call</param>
            /// <param name="stateChange">The new state</param>
            /// <param name="scope">Scope for the change</param>
            /// <param name="hardwareProfile">HardwareProfile to use</param>
            public void ChangeProperty(DIF installFunction, DICS stateChange, DICS_FLAGS scope, uint hardwareProfile)
            {
                var p = new SP_PROPCHANGE_PARAMS();

                p.ClassInstallHeader.cbSize          = (uint)Marshal.SizeOf(p.ClassInstallHeader);
                p.ClassInstallHeader.InstallFunction = installFunction;
                p.StateChange = stateChange;
                p.Scope       = scope;
                p.HwProfile   = hardwareProfile;
                var deviceInfo = this.deviceInfo;
                { //Set parameters
                    if (!SetupDiSetClassInstallParams(Handle, ref deviceInfo, ref p, (uint)Marshal.SizeOf(p)))
                    {
                        throw new Win32ErrorException();
                    }
                    KERNEL32.CheckLastError();
                }
                { //Run change
                    if (!SetupDiChangeState(Handle, ref deviceInfo))
                    {
                        throw new Win32ErrorException();
                    }
                    KERNEL32.CheckLastError();
                }
                //if (!SetupDiCallClassInstaller(installFunction, m_Handle, ref deviceInfo))
            }
Exemplo n.º 2
0
        /// <summary>
        /// Reads the window text of the specified control handle.
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        public static string GetWindowText(IntPtr handle)
        {
            var sb = new StringBuilder(64000);

            _ = USER32.GetWindowText(handle, sb, sb.Capacity);
            KERNEL32.CheckLastError();
            return(sb.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Installs both or one of mouse and/or keyboard hooks and starts rasing events
        /// </summary>
        /// <exception cref="Win32ErrorException">Any windows problem.</exception>
        public void Start()
        {
            // install Mouse hook only if it is not installed and must be installed
            if (hMouseHook == IntPtr.Zero)
            {
                // Create an instance of HookProc.
                mouseHookProcedure = new USER32.HookProc(MouseHookProc);
                //install hook
                hMouseHook = USER32.SetWindowsHookEx(WH.MOUSE_LL, mouseHookProcedure, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
                //If SetWindowsHookEx fails.
                KERNEL32.CheckLastError();
                if (hMouseHook == IntPtr.Zero)
                {
                    //do cleanup
                    Stop(false);
                    throw new Win32ErrorException();
                }
            }

            // install Keyboard hook only if it is not installed and must be installed
            if (hKeyboardHook == IntPtr.Zero)
            {
                // Create an instance of HookProc.
                keyboardHookProcedure = new USER32.HookProc(KeyboardHookProc);
                //install hook
                hKeyboardHook = USER32.SetWindowsHookEx(WH.KEYBOARD_LL, keyboardHookProcedure, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
                //If SetWindowsHookEx fails.
                KERNEL32.CheckLastError();
                if (hKeyboardHook == IntPtr.Zero)
                {
                    //do cleanup
                    Stop(false);
                    throw new Win32ErrorException();
                }
            }
        }