首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用inpout32.dll将Visual并行口应用程序转换为Delphi

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

Stack Overflow用户
提问于 2011-11-23 10:20:39
回答 2查看 6.8K关注 0票数 2

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

代码语言:javascript
复制
   '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访问同一个库吗?使用以下代码?

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

代码语言:javascript
复制
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;

我不清楚如何声明库函数,以及如何将变量声明为(&H 378显然不是整数)

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-11-23 10:34:51

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

代码语言:javascript
复制
//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;
票数 3
EN

Stack Overflow用户

发布于 2011-12-29 09:26:55

您应该使用inpout32.dll完全删除,因为它只用于直接访问打印机端口,并使代码转换复杂化。您可以使用德尔菲库更有效地完成同样的任务。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8240520

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档