Calculating cdplayer.ini id by algorithm

If you want to calculate the id - instead of using GetVolumeInformation - you may try this algorithm.
For Delphi sample and algorithm explanation, see here.
' Basic sample © Edy Hinzen 2001
Declare Function mciSendString Lib "WinMM" Alias "mciSendStringA" _
   (ByVal lpszCommand As String, _
    ByVal lpszString As String, _
    ByVal Stringlen As Integer, _
    ByVal hWnd As Long) As Integer

Function MilliSecsToFrames(milliSecs As Long) As Long
  Const FRAME_PER_SEC = 75
  Dim result As Long
  result = milliSecs * FRAME_PER_SEC \ 1000
  ' Did the division have a reminder? Then increment result by 1
  If milliSecs <> (result * 1000 \ FRAME_PER_SEC) Then result = result + 1
  MilliSecsToFrames = result
End Function

Sub MCIDemo()
  Dim iResult As Integer
  Dim sResult As String * 30
  Dim Min, Sec, frames As Long
  Dim dwTemp As Long
  Dim cdTotalTracks As Integer
  Dim magicNumb As Integer
  Dim cdLength As Long

  Dim driveLetter$
  driveLetter = "!P: " ' in this example, we use drive P:\
 'driveLetter = "" ' in this example, we use the first drive found

  iResult = mciSendString("Open CDAudio" & driveLetter & "alias CDAudio shareable wait", "", 0, 0)
  iResult = mciSendString("Status CDAudio Media Present wait", sResult, Len(sResult), 0)

  iResult = mciSendString("Status CDAudio Number of Tracks", sResult, Len(sResult), 0)
  cdTotalTracks = Val(sResult)

  iResult = mciSendString("Set CDAudio time format tfmsf wait", 0, 0, 0)

  dwTemp = 0
  magicNumb = 0

  For trackNum = 1 To cdTotalTracks
    iResult = mciSendString("Status CDAudio Position Track " & Str(trackNum), sResult, Len(sResult), 0)

    Min    = Val(Mid$(sResult, 1, 2))
    Sec    = Val(Mid$(sResult, 4, 2))
    frames = Val(Mid$(sResult, 7, 2))
    dwTemp  = dwTemp + ((Min * &H10000) + (Sec * &H100) + frames)

    If (trackNum = 1) And (cdTotalTracks = 2) Then magicNumb = frames
  Next trackNum

  If cdTotalTracks < 3 Then
    iResult = mciSendString("set CDAudio time format Milliseconds wait", 0, 0, 0)
    iResult = mciSendString("Status CDAudio Length", sResult, Len(sResult), 0)

    cdLength = MilliSecsToFrames(Val(sResult))

    dwTemp = dwTemp + magicNumb + cdLength
  End If

  MsgBox Hex(Str(dwTemp)) ' display result

  iResult = mciSendString("Close CDAudio", "", 0, 0)

End Sub

back to Q&A