使用inpout32.dll将Visual Basic并行端口应用程序转换为Delphi [英] Converting Visual Basic parallel port app using inpout32.dll in to Delphi

查看:149
本文介绍了使用inpout32.dll将Visual Basic并行端口应用程序转换为Delphi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

但是我需要在Delphi 5中将其重新编写才能集成到我的应用程序中。

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


  1. 是否可以访问通过D5使用同一个库吗?

  2. 我是使用以下代码在正确的方向吗?

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

//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;

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

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

谢谢

推荐答案

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

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;

这篇关于使用inpout32.dll将Visual Basic并行端口应用程序转换为Delphi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆