[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

a problem about API

Posted on 2001-07-06
4
Medium Priority
?
170 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month18 days, 16 hours left to enroll

834 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