Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to test if a CD is loaded in the cdrom ?

Status
Not open for further replies.
John;

You need to make a Win32API call:

Code:
PROCEDURE volumename
*!* This will return the volume name of a specified drive
*!* This will work with a floppy, hard disk, CD, or mapped network drive.

*!* Set lpRootPathName to the drive letter you want to check
lpRootPathName           = &quot;e:\&quot;      && Drive letter <<=======<

lpVolumeNameBuffer       = SPACE(256) && lpVolumeName return buffer
nVolumeNameSize          = 256        && Size of/lpVolumeNameBuffer
lpVolumeSerialNumber     = 0          && lpVolumeSerialNumber buffer
lpMaximumComponentLength = 256
lpFileSystemFlags        = 0
lpFileSystemNameBuffer   = SPACE(256)
nFileSystemNameSize      = 256

DECLARE INTEGER GetVolumeInformation IN Win32API AS GetVolInfo ;
	STRING  @lpRootPathName, ;
	STRING  @lpVolumeNameBuffer, ;
	INTEGER nVolumeNameSize, ;
	INTEGER @lpVolumeSerialNumber, ;
	INTEGER @lpMaximumComponentLength, ;
	INTEGER @lpFileSystemFlags, ;
	STRING  @lpFileSystemNameBuffer, ;
	INTEGER nFileSystemNameSize

lpVolumeNameBuffer=SPACE(11)

RetVal=GetVolInfo(@lpRootPathName, @lpVolumeNameBuffer, ;
	nVolumeNameSize, @lpVolumeSerialNumber, ;
	@lpMaximumComponentLength, @lpFileSystemFlags, ;
	@lpFileSystemNameBuffer, nFileSystemNameSize)


*!* lpVolumeNameBuffer will have the name of the mounted drive, if blank then drive is not mounted.
? lpVolumeNameBuffer


Hope this helps.

Ed

Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
Johnweida,

Once you have discovered that the user doesn't have a CD in the drive you can open the CD drawer for them so they can put a CD in :) (cut-n-paste the code below into a prg file and run it from within VFP)

Declare Long mciSendString in winmm as mciSendStringA string lpstrCommand, long lpstrReturnStr, Long wReturnLenLong, Long hCallBack
local intReturn, nfilehandle
=mciSendStringA( &quot;Set CDAudio Door Open Wait&quot;, 0, 0, 0)
intReturn = messagebox(&quot;Please insert a the CD and click OK&quot;, 0, &quot;Unable to locate CD...&quot;)
=mciSendStringA( &quot;Set CDAudio Door Closed Wait&quot;, 0, 0, 0)


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Slighthaze,

Your code works, but what if I have 2 or more DVD/CD drives? In my configuration, it opens the top CD. I cannot open the other drive tray. I tried changing one of those 0 parameters to 1 in order to get the other drive to open, but nothing worked and I looked for help or clues in vain on Microsoft's site. And if a user has 3 or more CD drives...

Sounds like a FAQ here would be nice, summarizing the posts here.
 
Some simple WSH code will also work to check for the drive being ready. (My CD drive is G:!)
Code:
oFSO=CreateObject('Scripting.FileSystemObject')
IF NOT oFSO.Drives('G').IsReady
   MessageBox('Drive G is not ready')
ENDIF
Rick
 
dbMark,

I have copied this from another recent thread I responded to...

Code to open whatever CD drawer you want to based on the drive letter. The code below assumes that you have CD drives H:\ and I:\, you will need to modify these to suit. Cut-n-paste the code below into a prg file and run it from within VFP.


LOCAL cCDDrive1, cCDDrive2
cCDDrive1 = &quot;H:\&quot;
cCDDrive2 = &quot;I:\&quot;
Declare Long mciSendString in winmm as mciSendStringA string lpstrCommand, long lpstrReturnStr, Long wReturnLenLong, Long hCallBack
mciSendStringA(&quot;Open &quot;+cCDDrive1+&quot; type CDAudio alias CDDrawer1&quot;, 0, 0, 0)
mciSendStringA(&quot;Set CDDrawer1 Door Open Wait&quot;, 0, 0, 0)
messagebox(&quot;Insert the CD and click OK.&quot;, 0, &quot;INSERT CD IN FIRST DRIVE&quot;)
mciSendStringA(&quot;Set CDDrawer1 Door Closed Wait&quot;, 0, 0, 0)
mciSendStringA(&quot;Open &quot;+cCDDrive2+&quot; type CDAudio alias CDDrawer2&quot;, 0, 0, 0)
mciSendStringA(&quot;Set CDDrawer2 Door Open Wait&quot;, 0, 0, 0)
messagebox(&quot;Insert the CD and click OK.&quot;, 0, &quot;INSERT CD IN SECOND DRIVE&quot;)
mciSendStringA(&quot;Set CDDrawer2 Door Closed Wait&quot;, 0, 0, 0)

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top