• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Delphi调用一些EXE,DLL

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Delphi调用一些EXE,DLL

1.调用EXE

 WINEXEC//调用可执行文件    
  winexec('command.com   /c   copy   *.*   c:\',SW_Normal);    
  winexec('start   abc.txt');    
  ShellExecute或ShellExecuteEx//启动文件关联程序    

uses   shellapi  
  shellexecute(application.Handle   ,'open','www.csdn.net,nil,nil,sw_normal);
  function   executefile(const   filename,params,defaultDir:string;showCmd:integer):THandle;    
  ExecuteFile('C:\abc\a.txt','x.abc','c:\abc\',0);    
  ExecuteFile('http://tingweb.yeah.net','','',0);    
  ExecuteFile('mailto:[email protected]','','',0);    

2.调用DLL

在Delphi中动态调用DLL 

动态调用DLL相对复杂很多,但非常灵活。
 
为了全面的说明该问题,这次我们举一个调用由C++编写的DLL的例子。首先在C++中编译下面的DLL源程序。 

#include 

extern ”C” _declspec(dllexport)

int WINAPI TestC(int i)

{

return i;

编译后生成一个DLL文件,在这里我们称该文件为Cpp.dll,该DLL中只有一个返回整数类型的函数TestC。为了方便说明,我们仍然引用上面的调用程序,只是将原来的Button1Click过程中的语句用下面的代码替换掉了。 

procedure TForm1.Button1Click(Sender: TObject);

type

TIntFunc=function(i:integer):integer;stdcall;

var

Th:Thandle;

Tf:TIntFunc;

Tp:TFarProc;

begin

Th:=LoadLibrary(’Cpp.dll’); {装载DLL}

if Th>0 then

try

Tp:=GetProcAddress(Th,PChar(’TestC’));

if Tp<>nil

then begin

Tf:=TIntFunc(Tp);

Edit1.Text:=IntToStr(Tf(1)); {调用TestC函数}

end

else

ShowMessage(’TestC函数没有找到’);

finally

FreeLibrary(Th); {释放DLL}

end

else

ShowMessage(’Cpp.dll没有找到’);

end; 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
用matlab绘制中国地图 - limanjihe发布时间:2022-07-18
下一篇:
MATLAB——m_map指南(1)发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap