I have written a service in VC++. I followed the tutorial here. Now, I am trying to find out how to receive messages like DBT_DEVICEARRIVAL, DBT_DEVICEREMOVECOMPLETE, WM_COPYDATA etc., just like a regular application that has a top level window. When searching for it, I came across this MSDN article
In the "Broadcasting Messages" section, in the final paragraphs:
Applications receive messages through the window procedure of their top-level windows. Messages are not sent to child windows. Services can receive messages through a window procedure or their service control handlers.
But it is almost impossible to find any example of how to do it.
How can I associate a WndProc with my service so that it receives messages?
Or, how can I make my service control handler function to receive windows messages? My service control handler has only one DWORD parameter and not the UINT, WPARAM, LPARAM etc of a WndProc.
I have read about 1) using a hidden window and 2) a message only window etc., but I don't think I can use them in a service; don't want to. It'd be happy if I can accomplish it in either of those two ways which MSDN mentions.
Description of service:
The service will detect USB device insertion and copy some files to it. It also has to keep track of changes to some directories and files so that it knows which ones to copy.
This basic functionality may be extended to include other things, in the future. So, I may have to be able to receive many other windows messages which I am not aware of now.
The example messages mentioned above are simply taken from what I am used to, when developing a regular windows app. I understand if they are not suitable or safe, when writing a service.