VB 型態宣告
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)
對應delphi
function Inp(PortAddress:Integer):integer;
type
TInp = function(PortAddress:Integer):integer; stdcall;
var
Lib : THandle;
Inp:TInp;
output:PAnsichar;
begin
output := AnsiStrAlloc(255);
Lib := LoadLibrary('inpout32.dll');
if Lib <> 0 then
begin
Inp := GetProcAddress(Lib, 'Inp32');
if Assigned(@Inp) then
begin
Result := Inp(PortAddress);
end;
end;
end;
procedure Out(PortAddress, Value:Integer);
type
TOut = procedure(PortAddress, Value:Integer); stdcall;
var
Lib : THandle;
Out:TOut;
output:PAnsichar;
begin
output := AnsiStrAlloc(255);
Lib := LoadLibrary('inpout32.dll');
if Lib <> 0 then
begin
Out := GetProcAddress(Lib, 'Out32');
if Assigned(@Out) then
begin
Out(PortAddress, Value);
end;
end;
end;
這樣就能成功引用了。