Using the message thread in a DLL/Framework


#1

One of my products is a framework/DLL that links to an application and does audio and MIDI stuff. I find it very difficult to use the Juce message thread. Messages posted to the message thread do never arrive at their Juce target objects. Probably because the application already catches them and discards them if they are of no use.

  • Do I need to flag the messages with some special intParameter1 in order to bypass the application and arrive at Juce MessageListeners?

  • Should I hack the application to make it skip Juce events in some way? (have the sources, although not my code)

  • Is this at all possible? I always wondered how the same works for Juce audio plugins that obviously get their events from the message thread despite the host application is also reading the system’s event queue. My plugins post messages to the message thread and receive them without problems.

Specifically for this purpose, I wrote a FakeMessageThread class that installs itself as the message thread, which worked ok, but consumed extraneous CPU power for some reason.

Any hint is highly appreciated!


#2

Hard to give any advice without knowing what the host app does in its message loop. The juce message loop will work just fine as long as the host doesn’t mess about or do anything stupid (e.g. it works in audio plugin hosts, and as a browser plugin, etc).


#3

Thanks. Then I probably should inspect the application’s sources and look whether it eats my events where it shoudn’t.

Do the Juce messages bear an “application specific” flag or something that I could use to filter them?


#4

No, but a host should never interfere with messages that get sent to a HWND that it doesn’t own.


#5

Ah thanks, the HWND may be the problem. I don’t have any window open, as the framework/DLL is headless.

That application also seems to grab and consume all messages it receives. I should probably tag my messages somehow (fake a HWND?) and hack the application’s event loop such that it will skip them and leave them in the event queue.

BTW: I managed to get past the CPU slowdown by lowering the priority of my FakeMessageThread from 7 to 4. Is there any need for using the real message thread at all, when a faked worker thread also does the job? (no GUI action required, just launch and shutdown of servers, midi outputs, and other shared resources)