Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-05-19
4
Medium Priority
?
504 Views
Last Modified: 2013-12-03
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
Comment
Question by:USBDev
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 24428172
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
 

Author Comment

by:USBDev
ID: 24447403
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
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 24468013
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
 

Author Closing Comment

by:USBDev
ID: 31583301
Thanks much this will be a huge help as well. Much appreciated.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question