DLL与EXE之间的恩爱情仇


本文整理自网络,侵删。

 
作者: 小坏
program Bin;
{$APPTYPE CONSOLE}
 
uses
  Windows;
   
Function RunApi(lpPorc :Pointer):Integer; Stdcall; external 'Test.Dll' name 'RunApi';
 
Var
  lpPorc :Pointer;
begin
  lpPorc := @MessageBoxW;// 这里可以自己动态加载需要的API
  RunApi(lpPorc);//传入API的内存地址
end.




library DLL;
 
Uses
  Windows;
 
Type
  TMyMessageBox = function(hWnd: HWND; lpText, lpCaption: LPCWSTR; uType: UINT): Integer; stdcall;
 
Function RunApi(lpPorc :Pointer):Integer;
Var
  pMessageBox :TMyMessageBox;
begin
  Result := -1;
  if Assigned(lpPorc) Then 
  begin
    pMessageBox := lpPorc;
    pMessageBox(0, 'Test', 'hahaha', 0);  //调用EXE传进来的API
    Result := 1;
  end;
end;
 
Exports
  RunApi;
 
begin
end.


通过以上代码可以在DLL中调用EXE中的API或函数

而DLL里只需要定义就行了

比如某Rat的EXE和DLL都带有通讯库这样会造成内存消耗的加大

以及DLL在动态传输时体积的增大

如果将EXE中的通讯库直接传入DLL然后由DLL直接调用进行操作体积可以减小很多
来源:https://www.7xcode.com/archives/110.html

相关阅读 >>

Delphi 测试磁盘是否具有写访问权限

Delphi mediaplayer1 设置音量

Delphi firedac 连接sql server一些要注意的地方

Delphi strutils.dupestring - 反复字符串

Delphi xe 获取 android application version 版本

delph控制台(console)程序添加图标和版权信息

Delphi 调出windows 系统时间设置对话框

Delphi 利用tcomm组件 spcomm 实现串行通信

Delphi inttohex

Delphi 限制文本框中只接受数字

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...