1
votes

I need to create a dll which manages some IP Bluetooth low-energy device on Windows 8.1 / 10.

My first challenge is to be able to intercept connection/disconnection events. I managed to achieve this by following MSDN's instructions for registering Bluetooth device notifications, and by following the Registering for Device Notifications example. The result is a working console app.

Next, I wish to wrap this in a DLL, and have a dedicated thread pump the message-only window's messages. Questions:

  • it this a reasonable solution, or am I better off using the calling thread to pump messages for this Window (which is obviously not single nor main)?

  • if this is the way to go, how do I create a thread that pumps messages for a specific Window?

  • can I simply rely on Thread Affinity, create the message-only Window in a new thread, and they will be coupled happily ever after?

1
Windows are very much thread-specifc, so using the calling thread won't work.Michaël Roy

1 Answers

3
votes

This sounds like a perfectly reasonable solution, it keeps your DLL from relying on whether the using application even runs a message loop, and even if that application does have a message loop it could conceivably use filtering to keep messages for your window from being picked up.

And yes, windows are coupled to the thread that creates them, each thread with a message loop maintains its own message queue.

So to have your thread receive messages for the window you need to have it create the window (presumably as part of the thread initialization before it drops into the message loop). Honestly this part is just like you see in a typical WinMain, just using a separate thread and message-only window.