我得到了这个简单的 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 中重新编写它以集成到我的应用程序中。
- 是否可以通过 D5 访问同一个库?
- 使用以下代码,我的方向是否正确?
//使用库的端口 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 显然不是整数)
谢谢