[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I know if there is a disk in a CD drive

Posted on 2009-12-23
15
Medium Priority
?
377 Views
Last Modified: 2013-12-14
Hi,
I have a program that eject a CD (for security reasons).
The problem is that I don't want to Eject the CD if there is no disk in it.
How can I know that?
0
Comment
Question by:VapiSoft
  • 9
  • 5
14 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26117838
You have your files on this CD?
Or looks for any file there or folder there and do not reject if there is nothing.
You can check the dos driver too with QueryDosDrivers - the name will say. But I think it is very easy to use FindFirstFile.
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26117858
I have to point you to your previous thread:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CPP/Q_25001253.html
In the beginning of your app find the CD-drive -  with QueryDosDevice and GetDriveType. Then, before you are going to eject the disk, look for a file there. If you can find at least one file - eject the disk.
 
0
 

Author Comment

by:VapiSoft
ID: 26117901
The problem is that the disk may be empty disk.
Actually, this is the normal case, that the user insert an empty disk to copy something on it (and this is what I want to prevent). So I cannot look for files on the disk.
0
Industry Leaders: 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!

 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26117916
So the disk name will ne something as "New Disk" or whatever
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26117921
Or you will have to go deeper and use something from the drivers
0
 

Author Comment

by:VapiSoft
ID: 26117925
No, I cannot assume anything on the disk name (it may even be unformatted).
I need something that detects if there is a CD disk inside.
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26117938
Also I think that you will have an exception when there is no CD and you try to use FindFileFirst. But you need to check yourself.
0
 

Author Comment

by:VapiSoft
ID: 26117949
But I will get the same exception if there is a disk and it is not formatted.
So it does not solve the problem.
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26117956
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26118004
I think you can use Shell:
SHGetSpecialFolderLocation
CSIDL
CodeProject: Extended Folder Browser
What will be if to ask for a free space: SHGetDiskFreeSpace() on the disk?
Is it a holiday today? :)
 
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26118142
Actually comment http:#a26117858 is the answer on your original question.
To detect if the CD inserted is formatted or not - better to ask in a relevant zone.
 
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26387013
I think comment http:#a26117858 is the answer on the origina question.
Then, with other conditions added, comments http:#a26117956 and  http:#a26118004 answer for these conditions.
 
0
 

Accepted Solution

by:
VapiSoft earned 0 total points
ID: 26388480
As I wrote, I eventually found the solution.
See the attached code.
Please close the question.
BOOL isDiskInCD(char drive)
{
	BOOL ok=0;
	DWORD junk;
	DISK_GEOMETRY dli;
	ZeroMemory(&dli, sizeof(dli));

 HANDLE h=OpenVolume(drive);
	if (h)
	{
		ok=DeviceIoControl(h,IOCTL_DISK_GET_DRIVE_GEOMETRY,
									NULL,0,
									&dli, sizeof(DISK_GEOMETRY),
									&junk,
									(LPOVERLAPPED) NULL);

		CloseHandle(h);
	}
	return ok;
}

Open in new window

0
 

Author Closing Comment

by:VapiSoft
ID: 31669719
I could not use it because I recived unresolved even when I added the shell32.lib.
So I used the
GetVolumeInformation
and it worked OK.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

834 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