I get an error when using blockinput

0

Hi, I am modifying a small application in c ++ that allows me to take control of my mouse and my keyboard, the code is as follows:

#include <windows.h>
#include <conio.h>
#include <stdio.h>


int main()
{
    HINSTANCE hDLL = LoadLibraryW (L"user32.dll");
    if (hDLL == NULL)
    {
        fprintf (stderr, "Failed to load user32.dll, error code %d\n", GetLastError());
        return 1;
    }


    typedef BOOL (WINAPI *BLOCKINPUT)(BOOL);
    BLOCKINPUT pBlockInput;
    pBlockInput = (BLOCKINPUT)GetProcAddress (hDLL, "BlockInput");
    if (pBlockInput == NULL)
    {
        fprintf (stderr, "Failed to import BlockInput, error code %d\n", GetLastError());
        FreeLibrary(hDLL);
        return 1;
    }

    else
    {
        BOOL res = pBlockInput (TRUE);
        if (!res) {
           fprintf (stderr, "BlockInput failed, error code %d\n", GetLastError());
        }
        Sleep (20);
    }



    FreeLibrary(hDLL);
    _getch();
}

The problem esque goes directly to the if it seems that the res variable is always false so I can not do what I'm trying:

What I want is that basically with blockinput for a while nobody can use my keyboard and mouse.

    
asked by Perl 29.01.2017 в 13:07
source

1 answer

2

The error 5 is:

  

ERROR_ACCESS_DENIED

The BlockInput( ) documentation does not indicate anything about it. However, from Windows Vista onwards, the use of the BlockInput function needs of the administrator privilege.

So the simplest solution is to run your program as Administrator .

    
answered by 29.01.2017 / 13:28
source