Solved

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

Posted on 2009-05-19
4
492 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
String manipulation in Visual Basic 7 81
DCT of  2D array using fftw in c++ 9 87
SSRS Deployment problem 5 90
why doesn't assert terminate here? 2 8
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

679 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