0

I have an USB device with CD Drive and storage volume. I can eject both of them or one by one. When I call CreateFileA to obtain handle of ejected volume, it returns a valid handle.

Have anyone idea, how to detect that volume is not ready for using?

UDP: I have an application, that can starts when the volume is already ejected. I want to identify state of the volume, when programm is running

EmmaStone
  • 23
  • 8
  • Please check [this solution](https://stackoverflow.com/questions/3918248/how-to-eject-a-usb-removable-disk-volume-similar-to-the-eject-function-in-win?rq=1) to see if it solves your issue. Specifically, the answer about setting the correct access when using `CreateFile`. – Das_Geek Apr 30 '19 at 13:23
  • @Das_Geek, `DeviceIoControl` with `FSCTL_IS_VOLUME_MOUNTED` for any cases returns non zero value, which means the volume is currently mounted. (But not plugged in, I guess) – EmmaStone Apr 30 '19 at 13:55

1 Answers1

0

A message of WM_DEVICECHANGE will notify applications of volume arrival and removal. Find the dbch_devicetype == DBT_DEVTYP_VOLUME.

There's an example on msdn.

Drake Wu
  • 6,927
  • 1
  • 7
  • 30