Chinaunix首页 | 论坛 | 博客
  • 博客访问: 759992
  • 博文数量: 112
  • 博客积分: 2581
  • 博客等级: 少校
  • 技术积分: 1229
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-18 13:05
个人简介

你撒下一粒善良的种_子, 会在暗中蔓延出一片灿烂的花海

文章分类

全部博文(112)

文章存档

2019年(4)

2018年(2)

2017年(1)

2016年(1)

2015年(3)

2014年(6)

2013年(6)

2012年(2)

2011年(20)

2010年(16)

2009年(28)

2008年(23)

分类:

2009-03-19 14:33:49

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.

 
阅读(1333) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~