• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 510
  • Last Modified:

Detecting a CD Eject Event while running a C++ program off a CD

Hi
     I'm running a C++ (TrollTech QT) program off a CD on a Windows machine.

If a user ejects the CD while the application is still running, I'm unable to detect the event through my program. Additionally my appilcation becomes unstable and I'm unable to gracefully handle any crashes that happen. Is it possible to do any of the below ...
1) detect CD eject event and prevent the CD eject while my application is running?
2) If #1 is not possible....then after CD is ejected , display a message to the user indicating that the CD has been ejected (This part may need to be loaded into memory.....but how) ??
0
USBDev
Asked:
USBDev
  • 2
  • 2
1 Solution
 
jkrCommented:
Well, you *can* detect the open event, but I am afraid this is not going to help you much. Once the tray is openend (and you cannot do much about it) your app is still to experience problems. I'd rather suggest to copy your app to a temporary folder and launch it from there.
0
 
USBDevAuthor Commented:
JKR .
   Thanks for your response. running the program off  hard disk is exactly what we are not to do. This is because there is confidential information on the CD which needs to remain on the CD. If we do copy on the hard disk we need to delete this data after the program is done and the user exits or the cd is ejected. Hence the problem.

Any other solutions /suggestions you hve are welcome.
We're also exploring spawning off seprate processes into memory which keep polling for files on a CD ...etct...etc.
0
 
jkrCommented:
OK, yet the notification event won't help you - you just will know that you're gonna crash soon. What you could do is locking the drive, so the user cannot open it, e.g.
HANDLE volume_handle;
volume_handle = CreateFile(
            "\\\\?\\C:",
            GENERIC_READ | GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            NULL,
            OPEN_EXISTING,
            NULL,
            NULL);
if (volume_handle == INVALID_HANDLE_VALUE)
      {
            printf("Failed to open handle to drive %c: - error code %u", drive, GetLastError());
            return 0;
      }
 
if (!DeviceIoControl(
            volume_handle,
            FSCTL_LOCK_VOLUME,
            NULL,
            0,
            NULL,
            0,
            &bytes_returned,
            NULL))
      {
          // error handling here
      }

Open in new window

0
 
USBDevAuthor Commented:
Thanks much this will be a huge help as well. Much appreciated.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now