?
Solved

a problem about API

Posted on 2001-07-06
4
Medium Priority
?
166 Views
Last Modified: 2010-04-06
I  used a api function GetVolumeInformation to get the volume serial number of a cd. and I found that I can not get the same value in the win98 os and win2000 os . why!!!
my code is below
procedure TForm1.Button1Click(Sender: TObject);
var
 dw1,dw2:dword;
 p:pDWORD;
begin
  try
    getmem(p,255);
    getvolumeinformation('g:\',nil,0,p,dw1,dw2,nil,0);
    edit1.Text:=inttostr(p^);
  finally
    freemem(p);
  end;
end;

I get two different edit1.text in win98 and win2000. but in fact they should be the same value.

who can help me to solve the problem

sincerely yours
lovedelphi

0
Comment
Question by:lovedelphi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
Motaz earned 300 total points
ID: 6261282
Try this solution:

Drop a Button, Label and  a MediaPlayer component. Make sure that MMSYstem is included in the Uses clause:


function GetCDInfo(ID: Integer; vWord: Word):String;
      var msp : TMCI_INFO_PARMS;
          MediaString : array[0..255] of char;
          ret : longint;
      begin
       FillChar(MediaString, SizeOf(MediaString), #0);
       FillChar(msp, sizeof(msp), #0);
       msp.lpstrReturn := @MediaString;
       msp.dwRetSize := 255;
       ret := mciSendCommand(ID,
                             MCI_INFO,
                             vWord,
                             longint(@msp));
       if Ret <> 0 then begin
         MciGetErrorString(ret, @MediaString, SizeOf(MediaString));
         Result := StrPas(MediaString);
       end else Result := StrPas(MediaString);
      end;

      function GetSerialNumber(ID: Integer): string;
      begin
       Result := GetCDInfo(ID, MCI_INFO_MEDIA_IDENTITY);
      end;



procedure TForm1.Button1Click(Sender: TObject);
begin
 MediaPlayer1.DeviceType:= dtCDAudio;
 MediaPlayer1.Open;
 Label1.Caption:= GetSerialNumber(MediaPlayer1.DeviceID);
end;

Motaz
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6261436
Hi lovedelphi,

wow, I just HAVE to help a guy with this name...   :-)

Please don't ask me why GetVolumeInformation returns different serial numbers under 9x and NT, I really don't know the reason. Motaz' suggestion (using MCI) is the correct solution. It gives you the same serial number in 9x and NT - well, in most cases at least. Recently I had a DVD ROM, which produced different MCI serial numbers, too. Sigh... But in most cases (at least for normal CDs) it works alright.

If you don't want to use the mediaPlayer, you can use my function, it needs less imports/uses:

function GetCDSerialNo(drive: char) : cardinal;
var mo    : TMCI_OPEN_PARMS;
    mp    : TMCI_INFO_PARMS;
    mg    : TMCI_GENERIC_PARMS;
    s1    : string;
    arrCh : array [0..255] of char;
begin
  result := 0;
  s1 := drive + ':';
  ZeroMemory(@mo, sizeOf(mo));
  ZeroMemory(@mp, sizeOf(mp));
  ZeroMemory(@mg, sizeOf(mg));
  mo.lpstrDeviceType  := pchar(MCI_DEVTYPE_CD_AUDIO);
  mo.lpstrElementName := pchar(s1);
  mp.lpstrReturn := arrCh;
  mp.dwRetSize   := sizeOf(arrCh) - 1;
  if mciSendCommand(0, MCI_OPEN,
                    MCI_OPEN_ELEMENT or MCI_OPEN_SHAREABLE or
                                        MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or MCI_WAIT,
                    cardinal(@mo)) = 0 then
    try
      if mciSendCommand(mo.wDeviceID, MCI_INFO, MCI_INFO_MEDIA_IDENTITY, cardinal(@mp)) = 0 then
        result := cardinal(StrToIntDef(arrCh, 0));
    finally mciSendCommand(mo.wDeviceID, MCI_CLOSE, 0, cardinal(@mg)) end;
end;

Regards, Madshi.
0
 

Author Comment

by:lovedelphi
ID: 6267727
thank you I got it!
0
 

Author Comment

by:lovedelphi
ID: 6267938
I can not give your score!!! how to...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question