使用 inpout32.dll 将 Visual Basic 并行端口应用程序转换为 Delphi

发布于 2024-12-17 12:11:51 字数 1851 浏览 3 评论 0原文

我得到了这个简单的 VB 应用程序和库,我被告知可以打开连接到 0x378 基地址的打印机端口的门/旋转样式。

   'Inp and Out declarations for port I/O using inpout32.dll.

Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" _
    (ByVal PortAddress As Integer) _
    As Integer

Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" _
    (ByVal PortAddress As Integer, _
    ByVal Value As Integer)

------------------------------------------------------------------------------------
Option Explicit
Dim Value As Integer
Dim PortAddress As Integer

Private Sub cmdWriteToPort_Click()
'Write to a port.
Out PortAddress, Value
'Read back and display the result.
Text1.Text = Inp(PortAddress)
Value = Value + 1
If Value = 255 Then Value = 0
End Sub

Private Sub Form_Load()
'Test program for inpout32.dll
Value = 0
'Change PortAddress to match the port address to write to:
'(Usual parallel-port addresses are &h378, &h278, &h3BC)
PortAddress = &H378
End Sub

但是我需要在 Delphi 5 中重新编写它以集成到我的应用程序中。

  1. 是否可以通过D5访问同一个库?
  2. 我使用以下代码的方向正确吗?

//使用库的端口 I/O 的 Inp 和 Out 声明

function Inp(PortAddress:String); external 'inpout32.dll.dll'
begin
 return ??
end;

procedure Output(PortAddress:String;Value:Integer); external 'inpout32.dll.dll'

procedure TForm1.FormActivate(Sender: TObject);
begin
//Test program for inpout32.dll

Value := 0;

//Change PortAddress to match the port address to write to:
//(Usual parallel-port addresses are &h378, &h278, &h3BC)

PortAddress := '&H378';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin

//Write to a port.
Output(PortAddress, Value);

//Read back and display the result.
Edit1.Text := Inp(PortAddress);
Value := Value + 1;

if Value = 255 then
Value := 0;

end;

我不确定如何声明库函数以及将变量声明为什么(&H378 显然不是整数)

谢谢

I've been given this simple VB application and library which I'm told can open a door/turnstyle attached to the printer port at 0x378 base address.

   'Inp and Out declarations for port I/O using inpout32.dll.

Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" _
    (ByVal PortAddress As Integer) _
    As Integer

Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" _
    (ByVal PortAddress As Integer, _
    ByVal Value As Integer)

------------------------------------------------------------------------------------
Option Explicit
Dim Value As Integer
Dim PortAddress As Integer

Private Sub cmdWriteToPort_Click()
'Write to a port.
Out PortAddress, Value
'Read back and display the result.
Text1.Text = Inp(PortAddress)
Value = Value + 1
If Value = 255 Then Value = 0
End Sub

Private Sub Form_Load()
'Test program for inpout32.dll
Value = 0
'Change PortAddress to match the port address to write to:
'(Usual parallel-port addresses are &h378, &h278, &h3BC)
PortAddress = &H378
End Sub

However I need to re-write it in Delphi 5 to integrate in to my application.

  1. Is it possible to access the same library through D5?
  2. Am I in the right direction with the following code?

//Inp and Out declarations for port I/O using library

function Inp(PortAddress:String); external 'inpout32.dll.dll'
begin
 return ??
end;

procedure Output(PortAddress:String;Value:Integer); external 'inpout32.dll.dll'

procedure TForm1.FormActivate(Sender: TObject);
begin
//Test program for inpout32.dll

Value := 0;

//Change PortAddress to match the port address to write to:
//(Usual parallel-port addresses are &h378, &h278, &h3BC)

PortAddress := '&H378';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin

//Write to a port.
Output(PortAddress, Value);

//Read back and display the result.
Edit1.Text := Inp(PortAddress);
Value := Value + 1;

if Value = 255 then
Value := 0;

end;

I'm not sure exactly how to declare the library functions and what to declare the variables as (&H378 is obviously not an integer)

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花落人断肠 2024-12-24 12:11:51

PortAddress 被声明为 Integer,因此不要使用字符串。您的代码应该如下所示:

//Inp and Out declarations for port I/O using inpout32.dll.
function Inp(PortAddress: Integer): Integer; stdcall; external 'inpout32.dll' name 'Inp32';

procedure Output(PortAddress, Value: Integer); stdcall; external 'inpout32.dll' name 'Out32';

procedure TForm1.FormActivate(Sender: TObject);
begin
  //Test program for inpout32.dll
  Value := 0;

  //Change PortAddress to match the port address to write to:
  //(Usual parallel-port addresses are $378, $278, $3BC)
  PortAddress := $378;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  //Write to a port.
  Output(PortAddress, Value);

  //Read back and display the result.
  Edit1.Text := IntToStr(Inp(PortAddress));
  Value := Value + 1;

  if Value = 255 then
    Value := 0;
end;

PortAddress is declared as an Integer, so don't use strings. Your code should look something like this:

//Inp and Out declarations for port I/O using inpout32.dll.
function Inp(PortAddress: Integer): Integer; stdcall; external 'inpout32.dll' name 'Inp32';

procedure Output(PortAddress, Value: Integer); stdcall; external 'inpout32.dll' name 'Out32';

procedure TForm1.FormActivate(Sender: TObject);
begin
  //Test program for inpout32.dll
  Value := 0;

  //Change PortAddress to match the port address to write to:
  //(Usual parallel-port addresses are $378, $278, $3BC)
  PortAddress := $378;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  //Write to a port.
  Output(PortAddress, Value);

  //Read back and display the result.
  Edit1.Text := IntToStr(Inp(PortAddress));
  Value := Value + 1;

  if Value = 255 then
    Value := 0;
end;
老街孤人 2024-12-24 12:11:51

您应该完全放弃使用inpout32.dll,因为它仅用于直接访问打印机端口并使您的代码转换复杂化。您可以使用 ZLOPTIO Delphi 库。

You should completely drop using inpout32.dll since it's only used to directly access printer port and complicates your code conversion. You can do the same much more efficient with ZLOPRTIO Delphi library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文