[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

a problem about API

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

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

650 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