CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2010
    Posts
    22

    Arrow CDs and Harddisk

    I'd like to access files on a CD and copy them into my Harddisk
    then automate the process to call windows player to process the Harddisk

    I am stuck at accsiing this CD

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: CDs and Harddisk

    I'd advise using the GetDriveType and GetLogicalDriveStrings APIs to assist in determining the CD ROM .

    With GetDriveType we ensure that there is indeed a CD rom present, and GetLogicalDriveStrings returns its Drive letter.

    Here is an example :
    Code:
    Private Declare Function GetDriveType Lib "kernel32" Alias _
          "GetDriveTypeA" (ByVal nDrive As String) As Long
    
    Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias _
          "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
          ByVal lpBuffer As String) As Long
    
    Private Const DRIVE_CDROM As Long = 5
    Private strDriveLetter As String
    
    Private Function GetFirstCdRomDriveLetter() As String
    
    ' Declare variables.
    Dim lDriveType As Long
    Dim strDrive As String
    Dim lStart As Long: lStart = 1
    
    ' Create a string to hold the logical drives.
    Dim strDrives As String
    strDrives = Space(150)
    
    ' Get the logial drives on the system.
    ' If the function fails it returns zero.
    Dim lRetVal As Long
    lRetVal = GetLogicalDriveStrings(150, strDrives)
    
    ' Check to see if GetLogicalDriveStrings() worked.
        If lRetVal = 0 Then
    
            ' Get GetLogicalDriveStrings() failed.
            GetFirstCdRomDriveLetter = vbNullString
            Exit Function
        End If
    
    ' Get the string that represents the first drive.
    strDrive = Mid(strDrives, lStart, 3)
    
        Do
    
            ' Test the first drive.
            lDriveType = GetDriveType(strDrive)
    
            ' Check if the drive type is a CD-ROM.
            
            If lDriveType = DRIVE_CDROM Then
    
                ' Found the first CD-ROM drive on the system.
                GetFirstCdRomDriveLetter = strDrive
                Exit Function
            End If
            
            ' Increment lStart to next drive in the string.
            lStart = lStart + 4
    
            ' Get the string that represents the first drive.
            strDrive = Mid(strDrives, lStart, 3)
    
            Loop While (Mid(strDrives, lStart, 1) <> vbNullChar)
    
    End Function
    
    Private Sub Command1_Click()
    MsgBox "CD ROM Located At " & strDriveLetter
    End Sub
    
    Private Sub Form_Load()
          
    ' Call the GetFirstCdRomDriveLetter() and store the
    ' return value in strDriveLetter.
    strDriveLetter = GetFirstCdRomDriveLetter()
            
    End Sub
    Once you have that in place, you could now use a timer to try to access a file on the particualr drive.

    Another way would be to use the RegisterDeviceNotification API to determine if a CD has been inserted. Not this way is very complicated, as you have to override several window procedures, to notify you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured