Get the UPC using mmsystem.dll

To get the universal product code (UPC) use mciSendCommand function with parameter mci_Info and flag MCI_INFO_MEDIA_UPC. This is the Delphi example (include unit MMSYSTEM in the USES-list):
procedure TForm1.FormCreate(Sender: TObject);
var
  InfoParm      : TMCI_Info_Parms;
  lpInfoString  : PChar;
const
  lenInfoString = 17;
begin
  { activate MediaPlayer1 to get the DeviceID }
  MediaPlayer1.DeviceType := dtCDAudio;
  if not MediaPlayer1.AutoOpen then MediaPlayer1.Open;

  { prepare record: }
  GetMem(lpInfoString,lenInfoString);
  InfoParm.dwCallback  := 0;
  InfoParm.lpstrReturn := lpInfoString;
  InfoParm.dwRetSize   := lenInfoString;
  { get UPC }
  mciSendCommand(MediaPlayer1.DeviceID,
                 mci_Info,
                 (mci_Wait or MCI_INFO_MEDIA_UPC),
                 Longint(@InfoParm) );
  { here's the result: (please read note below)}
  Edit1.Text := lpInfoString;
  FreeMem(lpInfoString,lenInfoString);
end;

Bad news:
Actually, a test series resulted in different values returned on each call. The values were "similar", like
00CC190EAB02C000 and
00CC191AAB02C000.

Whilst one drive gave some results, another drive on the same pc didn't. Besides this, the MCI documentations tell us that the UPC is not on every cd. Did we find a lottery routine or is something wrong with my code?


back to Q&A