- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
DLL与EXE之间的恩爱情仇
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