unresolved external symbol

  • Hi i need help with these type of errors:
    tecladoyraton.obj:-1: error: LNK2019: unresolved external symbol __imp__GetAsyncKeyState@4 referenced in function "short __cdecl comprobarTeclas(void)" (?comprobarTeclas@@YAFXZ)


    #include "../headers/tecladoyratonwin.h"
    #include <windows.h>
    void enviarTecla(int tecla)
    switch (tecla)
    case Qt::Key_Return:
    tecla = VK_RETURN;
    case Qt::Key_Backspace:
    tecla = VK_BACK;
    case Qt::Key_Escape:
    tecla = VK_ESCAPE;
    case Qt::Key_Shift:
    tecla = VK_SHIFT;
    case Qt::Key_CapsLock:
    tecla = VK_CAPITAL;
    keybd_event(tecla, 0, 0, 0);
    keybd_event(tecla, 0, KEYEVENTF_KEYUP, 0);
    void hacerClickDerechoP()
    mouse_event( MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0 );
    void hacerClickIzquierdoP()
    mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
    void hacerClickDerechoS()
    mouse_event( MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 );
    void hacerClickIzquierdoS()
    mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
    short comprobarTeclas()
    short i = 0;
    for(i = 0; i < 255; i++){
    if(GetAsyncKeyState(i) == -32767)
    return i;
    return 0;

    Code of header:

    #include <Qt>
    void enviarTecla(int tecla);
    void hacerClickDerechoP();
    void hacerClickIzquierdoP();
    void hacerClickDerechoS();
    void hacerClickIzquierdoS();
    short comprobarTeclas();

    [Moved to C++ Gurus ~kshegunov]

  • Lifetime Qt Champion


    You are not linking to the user32 library.

  • hi i included this library with this way: LIBS += -luser32 but still i get other error very similar MSVCRT.lib(crtexe.obj):-1: error: LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup How i could include this library. Thanks in advance. The user library was solved. Only need this MSVCRT.lib

  • Qt Champions 2017

    @RIVOPICO said in unresolved external symbol:

    LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

    You need to have a main() function[1] in your application.

    [1]: http://en.cppreference.com/w/cpp/language/main_function

  • Lifetime Qt Champion

    What exactly are you trying to develop ?

    Qt already provides keyboard and mouse handling.

  • but i included main in this code:

    #include <QApplication>
    #include "mainwindow.h"
    #include <Windows.h>
    #ifndef Q_WS_X11
    #include <QtPlugin>
    #ifdef _MSC_VER
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow)
        int argc = 0;
        char *argv[1];
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        MainWindow w;
        return a.exec();

    Maybe i need to change mi main ??

  • Qt Champions 2017

    @RIVOPICO said in unresolved external symbol:

    Maybe i need to change mi main ??

    No, you need to not use the WinAPI. Here I've given you the most basic of programs and there's no WinMain and there's no #ifdef, because they aren't needed nor at all useful in this case.

  • look this:
    i am trying to record my keyboard and mouse

  • Lifetime Qt Champion

    Please stop posting the same questions several times.

    This one ends up being exactly the same as this thread.

    Closing this one.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.