Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Currently I'm working on this example
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363432(v=vs.85).aspx
that helped me capture any changes in my hardware. (Like connecting and disconnecting a USB flash drive)

The sample explains that in order to enable my console project to compile this code I had to set Project->Properties->Linker->System->Subsystem to Windows

My main problem is that I require the project to stay like a console application.
Is there any way to run this code by a console application or shall I be using a whole new strategy?

Thanks
Posted
Updated 10-Sep-13 20:53pm
v2
Comments
Garth J Lancaster 10-Sep-13 6:31am    
The article suggests in the logic where the notifications are received, it could by performed differently if the code was being run from a service - so that suggests maybe a different mechanism - maybe a callback is possible.

If not, the next simplest way, is still within a console program, create a hidden window to get the message loop/receive the notifications
Garth J Lancaster 10-Sep-13 6:34am    
this page http://msdn.microsoft.com/en-us/library/windows/desktop/aa363431(v=vs.85).aspx suggests a service status handle - since you likely dont want to run as a service, I'd go with creating a hidden window from your console app

1 solution

As the article makes clear, you can only receive these notifications through a Windows message pump. That feature is not available in console applications.
 
Share this answer
 
Comments
Majid_Abdollahi 11-Sep-13 6:03am    
yes i know it but how can i detect usb insertion or removal by any way in win32 console application ??? anyone can help me by refer source example ?!
Richard MacCutchan 11-Sep-13 6:33am    
You cannot do it in a console application. Read my comments again, and the documentation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900