Reimplementing winEvent: getting stuck in API call
Page |
1 |
I am trying to build a bridge between two API:
- one communicates through sendMessages
- the other one is accessible through an activeX
This is what I do:
- HRESULT hr = pMJ.GetActiveObject(L"MediaJukebox Application");
- pPlayback = pMJ->GetPlayback();
- pPlayback->Play();
The Play() call works perfectly.
Then I connect a pushButton to a slot that will also call pPlayback->Play(), it works.
Finally I reimplement winEvent(…) to receive message from the other program.
- bool Bridge::winEvent(MSG *message, long *result)
- {
- if( message->message == WM_USER )
- {
- pPlayback->Play();
- *result = 0; // keep the event from qt
- return true;
- }
- // give the event to qt
- return false;
- }
In the meantime I can click my pushButton, and this one will work. But within winEven(…) it doesn’t.
What is the issue there? Am I triggering an infinite recursion?
19 replies
Thanks for your help.
How can I check the window that gets the message?
Bridge is a QMainWindow
EDIT: I tried a mutex-like in winEvent(…)
- if( message->message == WM_USER )
- {
- if( !CDArtMutex )
- CDArtMutex = true;
- else
- return false;
- pPlayback->Pause();
- emit handleCDArtEventUser((int)message->lParam, (int)message->wParam, result);
- *result = 0;
- CDArtMutex = false;
- return true;
- }
This does not solve the issue.
The point is that you only check one members of message…
message also more members:
- hwnd Handle to the window whose window procedure receives the message.
- message Specifies the message identifier.
- wParam Specifies additional information about the message. The exact meaning depends on the value of the message member.
- lParam Specifies additional information about the message. The exact meaning depends on the value of the message member.
- time Specifies the time at which the message was posted.
- pt Specifies the cursor position, in screen coordinates, when the message was posted.
you could compare hwnd with the winID() [doc.qt.nokia.com] of your main window.
Why the mutex does not work is also simple: if play doies not send the event but post it, it will arrive after you exited the event handler…
Each WM_USER evtn is handled by you regardless who is the receiver of the event. Afterwards you throw it away by returning true (handled).
And for each WM_USER event you call ->play().
I suggest the following:
- if( (message->message == WM_USER ) && (message->hwnd == winId()) )
- {
- pPlayback->Pause();
- emit handleCDArtEventUser((int)message->lParam, (int)message->wParam, result);
- *result = 0;
- return true;
- }
Doing this you only react on WM_USER messages send to Your window.
I will try to filter messages addressed to my winId.
But I still don’t understand why I have this strange behavior. I have run the msvc debugger step by step. When I reach play() and press the “next step” button, it never returns from play().
I simplified my code to post it in a more readable format. I already perform some filterning, but not on the winId. So maybe this will fix the issue.
EDIT: filtering with the winId() did not solve my issue…
You were right, everything stays in the main thread. How can I figure out if the COM control fires an event that is caught by winEvent in a recursive way?
With our without my stupid mutex, the test() call is never reached !?
- if( message->message == WM_USER && message->hwnd == winId() )
- {
- if( !CDArtMutex )
- {
- CDArtMutex=true;
- pPlayback->Play();
- test();
- CDArtMutex=false;
- *result = 0;
- return true;
- }
- else
- {
- // give the event to qt
- return false;
- }
- }
My code is really minimal but it is a bridge between 2 applications: if you want to test it you will have to fire messages. Keep in mind it is windows only.
I uploaded an archive here: hotfile [hotfile.com]
You will see that I got something working with QTimer::singleshot() but this is not a real solution since I can’t pass any arguments to my slots. So it is working for Play() but not for other calls.
Thanks again for your kind help!
You must log in to post a reply. Not a member yet? Register here!



