Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to get the virtual series number of an audio CD Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
30-Aug-02
Category
Multimedia
Language
Delphi 2.x
Views
102
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to get the virtual series number of an audio CD

Answer:

Answer 1:

Windows creates a "Virtual Series Number" for Audio CDs. You can use the following 
code to get the VSN of an audio CD:

1   type
2     TNumbBase = 1..36;
3   
4   function NumbToStr(Numb: LongInt; Base: TNumbBase): string;
5   const
6     NumbDigits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
7   begin
8     Result := EmptyStr;
9     while Numb > 0 do
10    begin
11      Result := NumbDigits[(Numb mod Base) + 1] + Result;
12      Numb := Numb div Base;
13    end;
14    if Result = EmptyStr then
15      Result := '0';
16  end;
17  
18  function GetCDID(Drive: string): string;
19  var
20    Serial: DWord;
21    T: Cardinal;
22  begin
23    if GetVolumeInformation(PChar(Drive), nil, 0, @Serial, T, T, nil, 0) then
24      Result := NumbToStr(Serial, 16)
25    else
26      Result := EmptyStr;
27  end;
28  
29  //Drive should be the name of the root directory of your CD drive. Use it like
30  
31  ShowMessage(GetCDID('I:\'));
32  
33  //or
34  
35  ShowMessage(GetCDID('\\Computer2\\CDDrive\'));



Solve 2:

You have to use the API-call GetVolumeInformation. But first, you have to implement 
it correctly:


function GetVolumeInformation(lpRootPathName: PAnsiChar; lpVolumeNameBuffer: 
PAnsiChar; nVolumeNameSize: DWORD; var lpVolumeSerialNumber, 
lpMaximumComponentLength,
lpFileSystemFlags: DWORD; lpFileSystemNameBuffer: PAnsiChar; nFileSystemNameSize: 
DWORD): bool; stdcall; external kernel32 name 'GetVolumeInformationA';


In your application:


36  function GetCDId: string;
37  var
38    root: string;
39    VolumeNameBuffer, FileSystemNameBuffer: PChar;
40    VolumeSerialNumber, FileSystemFlags, MaximumComponentLength: LongInt;
41  
42    function Int2Hex(number: LongInt): string;
43    var
44      i: LongInt;
45      s: string;
46    begin
47      s := '';
48      i := 0;
49      while number > 0 do
50      begin
51        i := number mod 16;
52        case i of
53          0..9: s := IntToStr(i) + s;
54          10: s := 'A' + s;
55          11: s := 'B' + s;
56          12: s := 'C' + s;
57          13: s := 'D' + s;
58          14: s := 'E' + s;
59          15: s := 'F' + s;
60        end;
61        number := number - i * 16;
62      end;
63      Result := s;
64    end;
65  
66  begin
67    root := 'x:\'; {where X is the drive letter of your CD drive}
68    VolumeNameBuffer := StrAlloc(256);
69    FileSystemNameBuffer := StrAlloc(256);
70    if GetVolumeInformation(PChar(root), VolumeNameBuffer, 255, VolumeSerialNumber,
71      MaximumComponentLength, FileSystemFlags, FileSystemNameBuffer, 255) then
72      Result := Int2Hex(VolumeSerialNumber);
73  else
74    Result := '';
75  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC