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)

    Code:

    #include "../headers/tecladoyratonwin.h"
    #include <windows.h>
    
    void enviarTecla(int tecla)
    {
    switch (tecla)
    {
    case Qt::Key_Return:
    tecla = VK_RETURN;
    break;
    case Qt::Key_Backspace:
    tecla = VK_BACK;
    break;
    case Qt::Key_Escape:
    tecla = VK_ESCAPE;
    break;
    case Qt::Key_Shift:
    tecla = VK_SHIFT;
    break;
    case Qt::Key_CapsLock:
    tecla = VK_CAPITAL;
    break;
    }
    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:

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

    [Moved to C++ Gurus ~kshegunov]


  • Lifetime Qt Champion

    Hi,

    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 2016

    @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>
    #endif
    
    #ifdef _MSC_VER
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow)
    {
        int argc = 0;
        char *argv[1];
    #else
    int main(int argc, char *argv[])
    {
    #endif
        QApplication a(argc, argv);
        MainWindow w;
        return a.exec();
    }
    

    Maybe i need to change mi main ??


  • Qt Champions 2016

    @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:
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx
    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.