当前位置: 首页 > news >正文

windows 核心编程DLL 高级技术-延迟载入dll,02

延迟载入DLL—测试程序

`
演示延迟载入DLL—测试程序

文章目录

  • 延迟载入DLL---测试程序
  • 演示延迟载入DLL---测试程序


演示延迟载入DLL—测试程序

/*------------------------------------------------------------------------20_ImportDelay.cpp演示延迟载入DLL---测试程序
-----------------------------------------------------------------------*/
#include <windows.h>
#include <tchar.h>
#include <strsafe.h>
#include <locale.h>
#include <Psapi.h> //For EnumProcessModules函数
#include "ExportDelay.h"//#pragma comment(lib,"psapi")
#pragma comment(lib,"20-Export-ImportDelay.lib")
//1、延迟加载是针对Dll的隐式链接的
//2、为了延迟加载Dll,还需要在解决方案的该项目“属性”->“配置属性”->
//“链接器”->“输入”->“延迟加载的Dll”中输入20_ImportDelay.dllvoid PrintModules(DWORD dwProcessID) {HMODULE* phMods = NULL;HANDLE hProcess = NULL;DWORD dwNeeded = 0;TCHAR szModName[MAX_PATH] = {};hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE, dwProcessID);if (NULL == hProcess) {_tprintf(_T("不能打开进程[ID:0x%X],错误码:[%u]\n"), dwProcessID,GetLastError());return;}//检索指定进程中每个模块的句柄EnumProcessModules(hProcess, NULL, 0, &dwNeeded);//获取所需字节数phMods = (HMODULE*)malloc(dwNeeded);if (EnumProcessModules(hProcess, phMods, dwNeeded, &dwNeeded)) {for (DWORD i = 0; i < (dwNeeded / sizeof(HMODULE)); i++) {ZeroMemory(szModName, MAX_PATH * sizeof(TCHAR));if (GetModuleFileNameEx(hProcess, phMods[i], szModName, MAX_PATH)) {_tprintf(_T("\t(0x%08X)\t%s\n"), (UINT)phMods[i], szModName);}}}free(phMods);CloseHandle(hProcess);
}int _tmain() {_tsetlocale(LC_ALL, _T("chs"));//显示进程中己加载的模块(此时不含(ExportDelay.dll)PrintModules(GetCurrentProcessId());_tsystem(_T("PAUSE"));int iVal1 = 10;int iVal2 = 20;int iVal3 = 30;_tprintf(_T("Func_A(%d)=%d\n"), iVal1, Func_A(iVal1));_tprintf(_T("Func_B(%d,%d)=%d\n"), iVal1, iVal2, Func_B(iVal1, iVal2));_tprintf(_T("Func_C(%d,%d,%d)=%d\n"), iVal1, iVal2, iVal3, Func_C(iVal1, iVal2, iVal3));PrintModules(GetCurrentProcessId());_tsystem(_T("PAUSE"));return 0;
}

http://www.mrgr.cn/news/13554.html

相关文章:

  • scrapy学习笔记0828-下
  • configure.ac和Makefile.am的格式解析概述
  • 【TPAMI 2024】Occlusion-Aware Self-Supervised Monocular 6D Object Pose Estimation
  • ES 根据条件删除文档
  • ARM 寻址方式(18)
  • 《黑神话:悟空》:文化与科技的完美融合
  • 阿里云服务器 篇七:服务器热备份/定时备份
  • Python简介、发展史
  • 前端引入字体文件
  • 秋招突击——知识复习——HTTP/2、HTTP/3的改良
  • 《Cloud Native Data Center Networking》(云原生数据中心网络设计)读书笔记 -- 08网络自动化
  • C#实现利用数据驱动设计与组件系统优化游戏架构示例
  • 牛客周赛 Round 35 (A~G)
  • 后端开发刷题 | 面试篇3
  • SSD300模型总结
  • 【PGCCC】PostgreSQL线程池技术揭秘:从原理到实战应用
  • 【busybox记录】【shell指令】nohup
  • iPhone 16 系列和多款新品将亮相,苹果发布会定档 9 月 10 日|TodayAI
  • 【2024】Datawhale AI夏令营-从零上手Mobile Agent-Task1笔记
  • Java中常用的API