Thema: Prism GetVolumeinformation

Einzelnen Beitrag anzeigen

Heffalump

Registriert seit: 3. Aug 2005
278 Beiträge
 
RAD-Studio 2009 Ent
 
#6

Re: GetVolumeinformation

  Alt 4. Dez 2006, 18:30
So würde ich das machen
Delphi-Quellcode:
unit DriveInfoUnit;

interface

uses

  System.Runtime.InteropServices,
  System.Text;
type
  DriveInfo = class(System.Object)
    strict private
    _name: System.String;
    [DllImport('kernel32.dll', CharSet=CharSet.Auto, SetLastError=true)]
    class function GetVolumeInformation(
      lpRootPathName: System.String;
      lpVolumeNameBuffer: StringBuilder;
      nVolumeNameSize: Integer;
      var lpVolumeSerialNumber: Integer;
      var lpMaximumComponentLength: Integer;
      var lpFileSystemFlags: Integer;
      lpFileSystemNameBuffer: StringBuilder;
      nFileSystemNameSize: Integer): boolean; static;
    [DLLImport('kernel32.dll')]
    class function GetLastError: Integer; static;
    public
      constructor Create(driveName: string);
    function get_VolumeLabel: String;
      property VolumeLabel: String read get_VolumeLabel;
  end;

implementation

{ DriveInfo }

constructor DriveInfo.Create(driveName: string);
begin
  inherited Create();
  if (driveName = nil) then
    raise NullReferenceException.Create('driveName');
  Self._name := driveName;
end;

class function DriveInfo.GetLastError: Integer;
begin

end;

class function DriveInfo.GetVolumeInformation(lpRootPathName: System.String;
  lpVolumeNameBuffer: StringBuilder; nVolumeNameSize: Integer;
  var lpVolumeSerialNumber, lpMaximumComponentLength,
  lpFileSystemFlags: Integer; lpFileSystemNameBuffer: StringBuilder;
  nFileSystemNameSize: Integer): boolean;
begin

end;

function DriveInfo.get_VolumeLabel: String;
var lpVolumeNameBuffer: StringBuilder;
    nVolumeNameSize: Integer;
    lpVolumeSerialNumber: Integer;
    lpMaximumComponentLength: Integer;
    lpFileSystemFlags: Integer;
    lpFileSystemNameBuffer: StringBuilder;
    nFileSystemNameSize: Integer;
begin
  nVolumeNameSize := 50;
  lpVolumeNameBuffer := StringBuilder.Create(nVolumeNameSize);
  nFileSystemNameSize := 50;
  lpFileSystemNameBuffer := StringBuilder.Create(nFileSystemNameSize);
  if not Self.GetVolumeInformation(
    Self._name,
    lpVolumeNameBuffer,
    nVolumeNameSize,
    lpVolumeSerialNumber,
    lpMaximumComponentLength,
    lpFileSystemFlags,
    lpFileSystemNameBuffer,
    nFileSystemNameSize) then
    begin
      raise ArgumentException.Create('ErrorCode: '+GetLastError.ToString);
    end else
    begin

      Result := lpVolumeNameBuffer.ToString;
    end;

end;

end.
  Mit Zitat antworten Zitat