unit comm;
interface
uses sysutils,dialogs,windows,strutils,classes;
Type
Tinp32=function(addr:integer):longint;stdcall;
Tout32=function(addr,data:integer):longint;stdcall;
var
inp32:tinp32;
out32:tout32;
aptr:Tfarproc;
th:Thandle;
syspath: array[0..255] of char;
implementation
function inp(addr:integer):byte;
begin
result:=Tinp32(inp32)(addr);
end;
function outp(addr,data:integer):byte;
begin
result:=Tout32(Out32)(addr,data);
end;
function ExtractRes(ResType, ResName, ResNewName: string): boolean;
var Res: TResourceStream;
begin
try
Res := TResourceStream.Create(Hinstance, Resname, Pchar(ResType));
try
Res.SavetoFile(ResNewName);
Result := true;
finally
Res.Free;
end;
except
Result := false;
end;
end;
procedure ExtractDLL ;
var syspath: array[0..255] of char;
begin
getsystemdirectory(syspath,255);
if not FileExists(syspath+'\inpout32.dll') then
begin
if not ExtractRes('dllfile','mydll',syspath+'\inpout32.dll') then
ExtractRes('dllfile','mydll','inpout32.dll');
end;
end;
initialization
getsystemdirectory(syspath,255);
ExtractDLL;
th:=loadlibrary(pchar(syspath+'\inpout32.dll'));
if th=0 then th:=loadlibrary('inpout32.dll');
if(th>0) then begin
out32:=getProcAddress(th,'Out32');
inp32:=getProcAddress(th,'Inp32');
end
else begin
raise exception.Create('Load inpout32.dll failed!');
end;
finalization
if th>0 then freeLibrary(th);
end.
阅读(1424) | 评论(0) | 转发(0) |