简体   繁体   English

在线程之间共享消息队列(在Windows中)

[英]Sharing message queues among threads (in Windows)

有没有什么方法可以在多个线程之间共享消息队列,或者以其他方式读取不同线程的消息队列,而无需使用钩子?

GetMessage and PeekMessage only read messages for the current thread, you can't use them to read messages sent to the input queue owned by another thread. GetMessage和PeekMessage仅读取当前线程的消息,您不能使用它们读取发送到另一个线程拥有的输入队列的消息。

Try joining the thread input queues using AttachThreadInput , that might work. 尝试使用AttachThreadInput加入线程输入队列,这可能会起作用。

Messages in a message queue can be differentiated on the basis of the window they're for, but I don't think messages can be differentiated on the basis of an inteded thread - the fields just aren't there in the MSG structure - so I don't think you can share a queue over multiple threads. 可以根据所使用的窗口来区分消息队列中的消息,但是我不认为可以基于整数线程来区分消息-MSG结构中不存在这些字段-因此我认为您不能在多个线程上共享一个队列。

That leaves you with a non-hook monitoring solution. 这为您提供了一个非挂钩的监视解决方案。

I'm pretty sure you could peek another threads queue, but the problem is you're basically polling; 我很确定您可以偷看另一个线程队列,但是问题是您基本上正在轮询; so you'll miss messages. 这样您会错过消息。

Do you have any influence over the threads you wish to read? 您对希望阅读的线程有影响吗? if so, you can get them to rebroadcast their messages to you. 如果是这样,您可以让他们重新广播他们的消息给您。

Apart from that, I can't see a way to do this. 除此之外,我看不到任何方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM