[Lazarus] Lazarus errors -- DVD procedure identifiers.

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Lazarus errors -- DVD procedure identifiers.

Peter Williams
Hi All,

I have a legacy Delphi 7 project which works fine in D7, but it gives these errors in Lazarus 0.9.31.

Options changed, recompiling clean with -B
Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.4.2-0 [2010/11/11] for i386
Copyright (c) 1993-2010 by Florian Klaempfl
Target OS: Linux for i386
Compiling Project1.lpr
Compiling DVDregion1.pas
DVDregion1.pas(62,13) Error: Identifier not found "ZeroMemory"
DVDregion1.pas(63,21) Error: Identifier not found "GetDriveType"
DVDregion1.pas(65,23) Error: Identifier not found "DRIVE_CDROM"
DVDregion1.pas(76,28) Error: Identifier not found "DeviceIoControl"
DVDregion1.pas(115) Fatal: There were 4 errors compiling module, stopping   


unit DVDregion1;

{$MODE Delphi}

interface

uses
  LCLIntf, LCLType, LMessages, Classes, SysUtils, Forms, StdCtrls, Controls;

type
  DVD_REGION = record
    CopySystem,
      RegionData, // current media region
    SystemRegion, // current drive region
    ResetCount: Byte;
  end;
  PDVD_REGION = ^DVD_REGION;

const
  IOCTL_DVD_GET_REGION = $335014;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.Button1Click(Sender: TObject);
const
  drive_letter = 'H:';
  RegionStrings: array[0..8] of string = (
    ' 0 --- No Region Code - works in any DVD player',
    ' 1 --- United States of America, Canada',
    ' 2 --- Europe, France, Greece, Turkey, Egypt, Arabia, Japan and South Africa',
    ' 3 --- Korea, Thailand, Vietnam, Borneo and Indonesia',
    ' 4 --- Australia, New Zealand, Mexico, the Caribbean, and South America',
    ' 5 --- India, Africa, Russia and former USSR countries',
    ' 6 --- Peoples Republic of China',
    ' 7 --- Unused',
    ' 8 --- Airlines and Cruise Ships');
var
  handle: THandle;
  rv, Region2Check: Integer;
  region: DVD_REGION;
  dw: DWORD;
  status: Boolean;
  Mask: byte;
begin
  Memo1.Clear;
  ZeroMemory(@region, SizeOf(DVD_REGION));
  rv := GetDriveType(drive_letter);

  if rv = DRIVE_CDROM then
    Memo1.Lines.Add('Drive is a CD/DVD drive');

  handle := FileCreate('\\.\' + drive_letter); { *Converted from CreateFile*  }

  if handle = INVALID_HANDLE_VALUE then
  begin
    Memo1.Lines.Add('Cannot open the drive');
    Exit;
  end;

  status := DeviceIoControl(
    handle, // handle to device
    IOCTL_DVD_GET_REGION, // dwIoControlCode
    nil, // lpInBuffer
    0, // nInBufferSize
    @region, // output buffer
    SizeOf(DVD_REGION), // buffer size
    dw, // number of bytes returned
    nil);

  if not status then
  begin
    FileClose(handle); { *Converted from CloseHandle*  }
    Memo1.Lines.Add('DevIoControl Failed');
    Exit;
  end;

  Memo1.Lines.Add('The Region and Code for this DVD :');
  Memo1.Lines.Add('');
  Memo1.Lines.Add('Code - Region');

  if region.RegionData and $3F = 0 then
    Memo1.Lines.Add(RegionStrings[0])
  else
  begin
    Mask := 1;
    for Region2Check := 1 to 8 do
    begin
      if region.RegionData and Mask = 0 then
        Memo1.Lines.Add(RegionStrings[Region2Check]);
      Mask := Mask shl 1;
    end;
  end;

  FileClose(handle); { *Converted from CloseHandle*  }
end;

end.

Best Regards,
Peter E Williams



--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus errors -- DVD procedure identifiers.

Daniel Franzini
It seems that these functions and constants you are using are from Windows unit.

Did you tried to include it in your uses clause?

2011/4/7 Peter Williams <[hidden email]>
Hi All,

I have a legacy Delphi 7 project which works fine in D7, but it gives these errors in Lazarus 0.9.31.

Options changed, recompiling clean with -B
Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.4.2-0 [2010/11/11] for i386
Copyright (c) 1993-2010 by Florian Klaempfl
Target OS: Linux for i386
Compiling Project1.lpr
Compiling DVDregion1.pas
DVDregion1.pas(62,13) Error: Identifier not found "ZeroMemory"
DVDregion1.pas(63,21) Error: Identifier not found "GetDriveType"
DVDregion1.pas(65,23) Error: Identifier not found "DRIVE_CDROM"
DVDregion1.pas(76,28) Error: Identifier not found "DeviceIoControl"
DVDregion1.pas(115) Fatal: There were 4 errors compiling module, stopping   


unit DVDregion1;

{$MODE Delphi}

interface

uses
  LCLIntf, LCLType, LMessages, Classes, SysUtils, Forms, StdCtrls, Controls;

type
  DVD_REGION = record
    CopySystem,
      RegionData, // current media region
    SystemRegion, // current drive region
    ResetCount: Byte;
  end;
  PDVD_REGION = ^DVD_REGION;

const
  IOCTL_DVD_GET_REGION = $335014;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.Button1Click(Sender: TObject);
const
  drive_letter = 'H:';
  RegionStrings: array[0..8] of string = (
    ' 0 --- No Region Code - works in any DVD player',
    ' 1 --- United States of America, Canada',
    ' 2 --- Europe, France, Greece, Turkey, Egypt, Arabia, Japan and South Africa',
    ' 3 --- Korea, Thailand, Vietnam, Borneo and Indonesia',
    ' 4 --- Australia, New Zealand, Mexico, the Caribbean, and South America',
    ' 5 --- India, Africa, Russia and former USSR countries',
    ' 6 --- Peoples Republic of China',
    ' 7 --- Unused',
    ' 8 --- Airlines and Cruise Ships');
var
  handle: THandle;
  rv, Region2Check: Integer;
  region: DVD_REGION;
  dw: DWORD;
  status: Boolean;
  Mask: byte;
begin
  Memo1.Clear;
  ZeroMemory(@region, SizeOf(DVD_REGION));
  rv := GetDriveType(drive_letter);

  if rv = DRIVE_CDROM then
    Memo1.Lines.Add('Drive is a CD/DVD drive');

  handle := FileCreate('\\.\' + drive_letter); { *Converted from CreateFile*  }

  if handle = INVALID_HANDLE_VALUE then
  begin
    Memo1.Lines.Add('Cannot open the drive');
    Exit;
  end;

  status := DeviceIoControl(
    handle, // handle to device
    IOCTL_DVD_GET_REGION, // dwIoControlCode
    nil, // lpInBuffer
    0, // nInBufferSize
    @region, // output buffer
    SizeOf(DVD_REGION), // buffer size
    dw, // number of bytes returned
    nil);

  if not status then
  begin
    FileClose(handle); { *Converted from CloseHandle*  }
    Memo1.Lines.Add('DevIoControl Failed');
    Exit;
  end;

  Memo1.Lines.Add('The Region and Code for this DVD :');
  Memo1.Lines.Add('');
  Memo1.Lines.Add('Code - Region');

  if region.RegionData and $3F = 0 then
    Memo1.Lines.Add(RegionStrings[0])
  else
  begin
    Mask := 1;
    for Region2Check := 1 to 8 do
    begin
      if region.RegionData and Mask = 0 then
        Memo1.Lines.Add(RegionStrings[Region2Check]);
      Mask := Mask shl 1;
    end;
  end;

  FileClose(handle); { *Converted from CloseHandle*  }
end;

end.

Best Regards,
Peter E Williams



--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus




--
Daniel

"Let us change our traditional attitude to the construction of programs. Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do." (Donald Knuth)

"Yes, technogeeks can be funny, even if only to each other." (http://www.boogieonline.com/revolution/science/humor/)"

"Man is driven to create; I know I really love to create things. And while I'm not good at painting, drawing, or music, I can write software." (Yukihiro Matsumoto, a.k.a. ``Matz'')

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus errors -- DVD procedure identifiers.

Peter Williams
Hi Daniel,


Date: Thu, 7 Apr 2011 17:20:51 -0300
From: [hidden email]
To: [hidden email]
Subject: Re: [Lazarus] Lazarus errors -- DVD procedure identifiers.

>It seems that these functions and constants you are using are from Windows unit.

>Did you tried to include it in your uses clause?

I need to get this working for Linux and cross-platform compiling. Is there a Linux equivalent of these procedures?

I think that maybe I can replace "ZeroMemory" with "FillChar"... what is the syntax?

What about GetDriveType, DRIVE_CDROM and DeviceIoControl ? Also what is the syntax for the Linux versions (cross platform) of these?

Best Regards,
Peter / pew

2011/4/7 Peter Williams <[hidden email]>
Hi All,

I have a legacy Delphi 7 project which works fine in D7, but it gives these errors in Lazarus 0.9.31.

Options changed, recompiling clean with -B
Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.4.2-0 [2010/11/11] for i386
Copyright (c) 1993-2010 by Florian Klaempfl
Target OS: Linux for i386
Compiling Project1.lpr
Compiling DVDregion1.pas
DVDregion1.pas(62,13) Error: Identifier not found "ZeroMemory"
DVDregion1.pas(63,21) Error: Identifier not found "GetDriveType"
DVDregion1.pas(65,23) Error: Identifier not found "DRIVE_CDROM"
DVDregion1.pas(76,28) Error: Identifier not found "DeviceIoControl"
DVDregion1.pas(115) Fatal: There were 4 errors compiling module, stopping   


unit DVDregion1;

{$MODE Delphi}

interface

uses
  LCLIntf, LCLType, LMessages, Classes, SysUtils, Forms, StdCtrls, Controls;

type
  DVD_REGION = record
    CopySystem,
      RegionData, // current media region
    SystemRegion, // current drive region
    ResetCount: Byte;
  end;
  PDVD_REGION = ^DVD_REGION;

const
  IOCTL_DVD_GET_REGION = $335014;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.Button1Click(Sender: TObject);
const
  drive_letter = 'H:';
  RegionStrings: array[0..8] of string = (
    ' 0 --- No Region Code - works in any DVD player',
    ' 1 --- United States of America, Canada',
    ' 2 --- Europe, France, Greece, Turkey, Egypt, Arabia, Japan and South Africa',
    ' 3 --- Korea, Thailand, Vietnam, Borneo and Indonesia',
    ' 4 --- Australia, New Zealand, Mexico, the Caribbean, and South America',
    ' 5 --- India, Africa, Russia and former USSR countries',
    ' 6 --- Peoples Republic of China',
    ' 7 --- Unused',
    ' 8 --- Airlines and Cruise Ships');
var
  handle: THandle;
  rv, Region2Check: Integer;
  region: DVD_REGION;
  dw: DWORD;
  status: Boolean;
  Mask: byte;
begin
  Memo1.Clear;
  ZeroMemory(@region, SizeOf(DVD_REGION));
  rv := GetDriveType(drive_letter);

  if rv = DRIVE_CDROM then
    Memo1.Lines.Add('Drive is a CD/DVD drive');

  handle := FileCreate('\\.\' + drive_letter); { *Converted from CreateFile*  }

  if handle = INVALID_HANDLE_VALUE then
  begin
    Memo1.Lines.Add('Cannot open the drive');
    Exit;
  end;

  status := DeviceIoControl(
    handle, // handle to device
    IOCTL_DVD_GET_REGION, // dwIoControlCode
    nil, // lpInBuffer
    0, // nInBufferSize
    @region, // output buffer
    SizeOf(DVD_REGION), // buffer size
    dw, // number of bytes returned
    nil);

  if not status then
  begin
    FileClose(handle); { *Converted from CloseHandle*  }
    Memo1.Lines.Add('DevIoControl Failed');
    Exit;
  end;

  Memo1.Lines.Add('The Region and Code for this DVD :');
  Memo1.Lines.Add('');
  Memo1.Lines.Add('Code - Region');

  if region.RegionData and $3F = 0 then
    Memo1.Lines.Add(RegionStrings[0])
  else
  begin
    Mask := 1;
    for Region2Check := 1 to 8 do
    begin
      if region.RegionData and Mask = 0 then
        Memo1.Lines.Add(RegionStrings[Region2Check]);
      Mask := Mask shl 1;
    end;
  end;

  FileClose(handle); { *Converted from CloseHandle*  }
end;

end.

Best Regards,
Peter E Williams



--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus




--
Daniel

"Let us change our traditional attitude to the construction of programs. Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do." (Donald Knuth)

"Yes, technogeeks can be funny, even if only to each other." (http://www.boogieonline.com/revolution/science/humor/)"

"Man is driven to create; I know I really love to create things. And while I'm not good at painting, drawing, or music, I can write software." (Yukihiro Matsumoto, a.k.a. ``Matz'')

-- _______________________________________________ Lazarus mailing list [hidden email] http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus errors -- DVD procedure identifiers.

Daniel Franzini


2011/4/7 Peter Williams <[hidden email]>
Hi Daniel,


Date: Thu, 7 Apr 2011 17:20:51 -0300
From: [hidden email]
To: [hidden email]
Subject: Re: [Lazarus] Lazarus errors -- DVD procedure identifiers.


>It seems that these functions and constants you are using are from Windows unit.

>Did you tried to include it in your uses clause?

I need to get this working for Linux and cross-platform compiling. Is there a Linux equivalent of these procedures?

Actually these seems to be very Windows specific. DeviceIOControl is the Windows mechanism to talk to devices at a lower level. I don't think one should have multiplataform versions of these.

Linux in fact has its own way of dealing with hardware in a low level fashion. For CD-ROM, specifically you have to search for SCSI commands. IIRC, Linux emulates a SCSI device for CDROMs. You may also search for ATAPI commands, which seems to be the commands that the OS sends and reads from the CDROM.

ZeroMemory is Windows-API. If you prefer, FillChar should be enough given proper syntax. And please, if this code is for production environments, get yourself concerned about security issues on using such APIs.
 

I think that maybe I can replace "ZeroMemory" with "FillChar"... what is the syntax?

What about GetDriveType, DRIVE_CDROM and DeviceIoControl ? Also what is the syntax for the Linux versions (cross platform) of these?

Best Regards,
Peter / pew


--
Daniel

"Let us change our traditional attitude to the construction of programs. Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do." (Donald Knuth)

"Yes, technogeeks can be funny, even if only to each other." (http://www.boogieonline.com/revolution/science/humor/)"

"Man is driven to create; I know I really love to create things. And while I'm not good at painting, drawing, or music, I can write software." (Yukihiro Matsumoto, a.k.a. ``Matz'')

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus errors -- DVD procedure identifiers.

Marco van de Voort
In reply to this post by Peter Williams
In our previous episode, Peter Williams said:
> I have a legacy Delphi 7 project which works fine in D7, but it gives these errors in Lazarus 0.9.31.
> Options changed, recompiling clean with -BHint: Start of reading config file /etc/fpc.cfgHint: End of reading config file /etc/fpc.cfgFree Pascal Compiler version 2.4.2-0 [2010/11/11] for i386Copyright (c) 1993-2010 by Florian KlaempflTarget OS: Linux for i386Compiling Project1.lprCompiling DVDregion1.pasDVDregion1.pas(62,13) Error: Identifier not found "ZeroMemory"DVDregion1.pas(63,21) Error: Identifier not found "GetDriveType"DVDregion1.pas(65,23) Error: Identifier not found "DRIVE_CDROM"DVDregion1.pas(76,28) Error: Identifier not found "DeviceIoControl"DVDregion1.pas(115) Fatal: There were 4 errors compiling module, stopping  

Looks like a windows only project, with the windows unit headers stripped.
WIll probably work fine with Lazarus under Windows.



--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus errors -- DVD procedure identifiers.

Lukasz Sokol
On 08/04/2011 11:08, Marco van de Voort wrote:
> In our previous episode, Peter Williams said:
>> I have a legacy Delphi 7 project which works fine in D7, but it gives these errors in Lazarus 0.9.31.
>> Options changed, recompiling clean with -BHint: Start of reading config file /etc/fpc.cfgHint: End of reading config file /etc/fpc.cfgFree Pascal Compiler version 2.4.2-0 [2010/11/11] for i386Copyright (c) 1993-2010 by Florian KlaempflTarget OS: Linux for i386Compiling Project1.lprCompiling DVDregion1.pasDVDregion1.pas(62,13) Error: Identifier not found "ZeroMemory"DVDregion1.pas(63,21) Error: Identifier not found "GetDriveType"DVDregion1.pas(65,23) Error: Identifier not found "DRIVE_CDROM"DVDregion1.pas(76,28) Error: Identifier not found "DeviceIoControl"DVDregion1.pas(115) Fatal: There were 4 errors compiling module, stopping  
>
> Looks like a windows only project, with the windows unit headers stripped.
> WIll probably work fine with Lazarus under Windows.
>
Would it run on WINE ?

Lukasz


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus errors -- DVD procedure identifiers.

Marco van de Voort
On Fri, Apr 08, 2011 at 12:05:33PM +0100, Lukasz Sokol wrote:
> > In our previous episode, Peter Williams said:
> >> I have a legacy Delphi 7 project which works fine in D7, but it gives these errors in Lazarus 0.9.31.
> >> Options changed, recompiling clean with -BHint: Start of reading config file /etc/fpc.cfgHint: End of reading config file /etc/fpc.cfgFree Pascal Compiler version 2.4.2-0 [2010/11/11] for i386Copyright (c) 1993-2010 by Florian KlaempflTarget OS: Linux for i386Compiling Project1.lprCompiling DVDregion1.pasDVDregion1.pas(62,13) Error: Identifier not found "ZeroMemory"DVDregion1.pas(63,21) Error: Identifier not found "GetDriveType"DVDregion1.pas(65,23) Error: Identifier not found "DRIVE_CDROM"DVDregion1.pas(76,28) Error: Identifier not found "DeviceIoControl"DVDregion1.pas(115) Fatal: There were 4 errors compiling module, stopping  
> >
> > Looks like a windows only project, with the windows unit headers stripped.
> > WIll probably work fine with Lazarus under Windows.
> >
> Would it run on WINE ?

Maybe it would run in a VM too, but that is besides the point. Then you
might as well run the D7 binary in whatever emulator.

Anyway, since this is hardware detection, even Wine might not help you here.

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus