samedi 28 avril 2018

How to use GetMessage to read another Thread's message queue

I'm trying to run a trhead in the background which reads the message queue from the main thread, so I can focus on installing and uninstalling hooks and responding to user actions, but I can't make the second thread poll from the main thread's message queue. I searched for a solution but didn't find any answer which solves my problem. Does anyone here know what to do? thanks in advance!

this is the code I wrote: (the Macro_Record hook increase counter everytime it is called)

int counter = 0;
MSG stam;

void Init(DWORD main_id)

{
     DWORD cur_id = GetCurrentThreadId();
     int result = AttachThreadInput(main_id, cur_id, true);
     if (!result)
     {
         cout << "Threads not attached " << result << endl;
     }
     else
     {
         cout << "Threads attached " << result << endl;
     }
     while (GetMessage(&stam, NULL, 0, 0));
}


int main()
{
    DWORD id = GetCurrentThreadId();
    HANDLE hthread;
    hthread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Init,(LPVOID)id, 0, NULL);
    if (hthread == NULL)
    {
        cout << "Thread failed" << endl;
    }
    else
    {
        cout << "Thread Success" << endl;
    }
    /*string ans;
    cout << "Enter path to file you want to open" << endl;
    getline(cin, ans);*/
    File_Run* calc= new File_Run("C:\python27\python.exe", "open");
    Macro calc_macro(calc, false, false);
    recording = &calc_macro;
    HHOOK record_handle =SetWindowsHookEx(WH_KEYBOARD_LL, Macro_Record, NULL, NULL);
    if (record_handle == NULL)
    {
        cout << "Install record failed" << endl;
        cout << GetLastError() << endl;
    }
    else
    {
        cout << "Record success, start typing" << endl;
        while (counter < 8);

Aucun commentaire:

Enregistrer un commentaire