本文整理自网络,侵删。
作者: 小坏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; beginend.
通过以上代码可以在DLL中调用EXE中的API或函数
而DLL里只需要定义就行了
比如某Rat的EXE和DLL都带有通讯库这样会造成内存消耗的加大
以及DLL在动态传输时体积的增大
如果将EXE中的通讯库直接传入DLL然后由DLL直接调用进行操作体积可以减小很多来源:https://www.7xcode.com/archives/110.html
相关阅读 >>
Delphi 10.3 处理csv tstreamreader 自带split用法
Delphi 2009 之 tcategorypanelgroup[3]: color
更多相关阅读请进入《Delphi》频道 >>