Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.3 KiB

  1. #define NOOLE
  2. #include <windows.h> /* required for all Windows applications */
  3. #include <windowsx.h>
  4. #include <strsafe.h>
  5. #include <mmsystem.h> /* all the MCI stuff */
  6. #include <stdio.h>
  7. // Uses the MCI_STATUS command to get and display the
  8. // starting times for the tracks on a compact disc.
  9. // Returns 0L if successful; otherwise, it returns an
  10. // MCI error code.
  11. DWORD getCDTrackStartTimes()
  12. {
  13. UINT wDeviceID;
  14. int i, iNumTracks;
  15. DWORD dwReturn;
  16. DWORD dwPosition;
  17. char szTempString[64];
  18. char szTimeString[512] = "\0"; // room for 20 tracks
  19. MCI_OPEN_PARMS mciOpenParms;
  20. MCI_SET_PARMS mciSetParms;
  21. MCI_STATUS_PARMS mciStatusParms;
  22. // Open the device by specifying the device name.
  23. mciOpenParms.lpstrDeviceType = "cdaudio";
  24. if (dwReturn = mciSendCommand(NULL, MCI_OPEN,
  25. MCI_OPEN_TYPE, (DWORD)(LPVOID) &mciOpenParms))
  26. {
  27. // Failed to open device.
  28. // Don't close device; just return error.
  29. return (dwReturn);
  30. }
  31. // The device opened successfully; get the device ID.
  32. wDeviceID = mciOpenParms.wDeviceID;
  33. // Set the time format to minute/second/frame (MSF) format.
  34. mciSetParms.dwTimeFormat = MCI_FORMAT_MSF;
  35. if (dwReturn = mciSendCommand(wDeviceID, MCI_SET,
  36. MCI_SET_TIME_FORMAT,
  37. (DWORD)(LPVOID) &mciSetParms))
  38. {
  39. mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
  40. return (dwReturn);
  41. }
  42. // Get the number of tracks;
  43. // limit to number that can be displayed (20).
  44. mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
  45. if (dwReturn = mciSendCommand(wDeviceID, MCI_STATUS,
  46. MCI_STATUS_ITEM, (DWORD)(LPVOID) &mciStatusParms))
  47. {
  48. mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
  49. return (dwReturn);
  50. }
  51. iNumTracks = mciStatusParms.dwReturn;
  52. // For each track, get and save the starting location and
  53. // build a string containing starting locations.
  54. for(i=1; i<=iNumTracks; i++)
  55. {
  56. printf("Track %2d -", i);
  57. //
  58. // get/print the start address
  59. //
  60. mciStatusParms.dwItem = MCI_STATUS_POSITION;
  61. mciStatusParms.dwTrack = i;
  62. if (dwReturn = mciSendCommand(wDeviceID,
  63. MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK,
  64. (DWORD)(LPVOID) &mciStatusParms))
  65. {
  66. mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
  67. return (dwReturn);
  68. }
  69. printf(" %02d:%02d:%02d",
  70. MCI_MSF_MINUTE(mciStatusParms.dwReturn),
  71. MCI_MSF_SECOND(mciStatusParms.dwReturn),
  72. MCI_MSF_FRAME(mciStatusParms.dwReturn)
  73. );
  74. //
  75. // get/print the track length
  76. //
  77. mciStatusParms.dwItem = MCI_STATUS_LENGTH;
  78. mciStatusParms.dwTrack = i;
  79. if (dwReturn = mciSendCommand(wDeviceID,
  80. MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK,
  81. (DWORD)(LPVOID) &mciStatusParms))
  82. {
  83. mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
  84. return (dwReturn);
  85. }
  86. printf(" %02d:%02d:%02d",
  87. MCI_MSF_MINUTE(mciStatusParms.dwReturn),
  88. MCI_MSF_SECOND(mciStatusParms.dwReturn),
  89. MCI_MSF_FRAME(mciStatusParms.dwReturn)
  90. );
  91. //
  92. // get/print if it's audio or data
  93. //
  94. mciStatusParms.dwItem = MCI_CDA_STATUS_TYPE_TRACK ;
  95. mciStatusParms.dwTrack = i;
  96. if (dwReturn = mciSendCommand(wDeviceID,
  97. MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK,
  98. (DWORD)(LPVOID) &mciStatusParms))
  99. {
  100. mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
  101. return (dwReturn);
  102. }
  103. if (mciStatusParms.dwReturn == MCI_CDA_TRACK_AUDIO) {
  104. printf(" (audio)\n");
  105. } else {
  106. printf(" (data )\n");
  107. }
  108. }
  109. // Free memory and close the device.
  110. if (dwReturn = mciSendCommand(wDeviceID,
  111. MCI_CLOSE, 0, NULL))
  112. {
  113. return (dwReturn);
  114. }
  115. return (0L);
  116. }
  117. __cdecl
  118. main(UINT Argc, UCHAR *Argv[])
  119. {
  120. // Use MessageBox to display starting times.
  121. printf("Disc Info\n");
  122. getCDTrackStartTimes();
  123. return;
  124. }