1,105,242 Community Members

Detecting new usb removable devices using c++

Member Avatar
Awah Mohamed
Junior Poster
176 posts since Jul 2010
Reputation Points: -5 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi guys, how are you?
Well, i have my science fair soon and i want to build a software that can copy any given file to any removable device that gets connected to the computer it is running on.. But the problem is i dont know how to do this... I am not that good in c++... So please help me..

In a simpler way, i am trying to write a c++ function that can copy lets say the file "exam.pdf" to any usb device that gets connected to the computer running the software containing that function.. How can i do it?? I looked on google and nothing useful came to me... Please people help me! And i will be greatful to anyone who will try to help!!

Member Avatar
Awah Mohamed
Junior Poster
176 posts since Jul 2010
Reputation Points: -5 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

The function should do everything automatically.. Like it should automatically detect the new device and automatically send to it the file...

Member Avatar
BobS0327
Posting Whiz in Training
203 posts since Feb 2008
Reputation Points: 24 [?]
Q&As Helped to Solve: 29 [?]
Skill Endorsements: 0 [?]
 
0
 

You have to handle the WM_DEVICECHANGE message in the window procedure of the application. The WPARAM will be the device change event such as DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE. LPARAM is a pointer to the device broadcast header. You can detect the device type which is stored in the dbch_devicetype member of PDEV_BROADCAST_HEADER.

There is one "gotcha" with this scenario. The system will only send a WM_DEVICECHANGE message to the application with a top level window. To eliminate this "gotcha", you must use the RegisterDeviceNotification function to allow your app to be notified upon any interface changes. Thus, allowing your application to receive the WM_DEVICECHANGE message even if it is not a top level window.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: