[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [ProgSoc] Windows thread communication?



Title: RE: [ProgSoc] Windows thread communication?

> I'm trying to get two threads to communicate in Windows <SHUDDER>. I'm
> using PostThreadMessage in one thread and PeekMessage in the other
> thread.  PostThreadMessage fails and GetLastError() returns 1159:
> ERROR_MESSAGE_SYNC_ONLY which MSDN tells me means the message can only
> be used with synchronous operations. What does this mean? I thought
> that PostThreadMessage allowed asynchronous communication between
> threads. Any ideas why this happens? Or how else can I send a message
> from one thread to the other without the first thread blocking?

The error you are getting may have something to do with the message you are sending. Some messages are designed for returning values only. For example, WM_QUERYDRAGICON returns a HICON or HCURSOR - posting this message makes no sense because the handle will be lost. I'd recommend using values WM_APP or higher because they are guaranteed not to conflict with any system or control messages.

Is there any particular reason for using a message loop? Generally speaking, unless you need to use a message loop (eg if the destination thread has one or more windows associated with it), I'd recommend using a mailslot or pipe instead. They are thread safe and have has less overhead.

Anthony Langsworth
Software Developer
mailto:anthonyl@nospam.computingedge.com.au