通过VirtualQuery查询当前进程虚拟内存使用情况
来源:互联网 发布:测男女软件下载 编辑:程序博客网 时间:2024/05/23 18:33
函数原型:
SIZE_T WINAPI VirtualQuery( _In_opt_ LPCVOID lpAddress, _Out_ PMEMORY_BASIC_INFORMATION lpBuffer, _In_ SIZE_T dwLength);
源代码:
#include<stdio.h>#include<Windows.h>/*** 数据类型总结:BSTR:OLECHAR * 类型的Unicode字符串,时一个COM字符串,带长度前缀。LPSTR: char*,指向以"\0"结尾的8位(单字节)ANSI字符数组指针LPWSTR: wchar_t *,指向以 "\0"结尾的16位(双字节)Unicode字符数组指针LPCSTR: const char *LPCWSTR: const wchar_t*LPTWSTR: LPSTR,LPWSTR二选一,取决于 宏是否定义 ASNSI,Unicode相互转换的方法:LPWSTR->LPSTR: W2T()LPTSRT->LPWSTR : T2W()LPCWSTR->LPCSTR:W2CT()LPCSTR->LPCWSTR:T2CW()ANSI->UNICODE:A2W()UNICODE->ANSI:W2A()------------------------------输出宽字符(Unicode)的正确方式:wchar_t buf[100]=L"123"; printf("%ls",buf)**/int main(int argc, char * argv[]){LPCVOID pAddress = 0x00;MEMORY_BASIC_INFORMATION memInfo;char Type[10];char Protect[10];wchar_t dlpath[1024];while (VirtualQuery(pAddress, &memInfo, sizeof(memInfo)) != 0){ZeroMemory(Type, 10);ZeroMemory(Protect, 10);ZeroMemory(dlpath, 1024);printf("基地址:0x%p |", memInfo.BaseAddress);if (memInfo.State == MEM_FREE){sprintf(Type, "FREE");}else if (memInfo.Type == MEM_IMAGE){sprintf(Type, "Image");}else if (memInfo.Type == MEM_MAPPED){sprintf(Type, "mapped");}else if (memInfo.Type==MEM_PRIVATE){sprintf(Type, "private");}printf(" %s |", Type);printf(" %d |", memInfo.RegionSize);if (memInfo.AllocationProtect == PAGE_READONLY){sprintf(Protect, "_R_");}else if (memInfo.AllocationProtect == PAGE_READWRITE){sprintf(Protect, "_RW_");}else if (memInfo.AllocationProtect == PAGE_EXECUTE){sprintf(Protect, "_E_");}else if (memInfo.AllocationProtect == PAGE_EXECUTE_READWRITE){sprintf(Protect, "_ERW_");}else if (memInfo.AllocationProtect == PAGE_EXECUTE_READ){sprintf(Protect, "_ER_");}else if (memInfo.AllocationProtect == PAGE_EXECUTE_WRITECOPY){sprintf(Protect, "_ERC_");}printf(" %s |", Protect);if (memInfo.AllocationProtect==PAGE_EXECUTE_WRITECOPY){DWORD r=GetModuleFileName((HMODULE)memInfo.AllocationBase, dlpath, sizeof(dlpath));}printf(" %ls ", dlpath);printf("\n");//换行pAddress = (PVOID)((PBYTE)pAddress + memInfo.RegionSize);//指针运算 先转PBYTE是因为 RegionSize是Byte}while (1);}
注意:1.这里是根据 RegionSize每次查询下一个区域的 位置,直到VirtualQuery 返回值为0.
2.还需要注意的是 LPWSTR是宽字符指针(Unicode),也就是wchar_t 指针,需要 %ls 格式化输出。。
阅读全文
0 0
- 通过VirtualQuery查询当前进程虚拟内存使用情况
- 通过VirtualQuery获取当前模块的句柄
- 用VMQuery查询虚拟地址空间(虚拟内存)的使用情况
- windows查询端口使用情况以及根据PID查询进程
- 查询mysql当前连接情况
- 使用VirtualQuery查看内存页面信息
- 使用VirtualQuery查看内存页面信息
- 通过GlobalMemoryStatus函数获取当前虚拟内存和物理内存信息
- 进程虚拟内存
- 进程虚拟内存
- Android使用adb查看当前设备运行进程CPU内存等资源的使用情况
- Android使用adb查看当前设备运行进程CPU内存等资源的使用情况
- 计算当前Exchange 2010 数据库的用户使用情况,通过PS命令行!
- oracle查询当前用户的连接情况
- 查看当前目录使用情况
- 通过进程号杀死进程或查询进程以及使用案例
- Eclipse虚拟内存设置 和 查看使用情况 方法
- 通过端口查找进程占用情况
- Redis配置和常用命令
- COOKIE
- 宏定义交换函数-交换两个数的值
- QT中的.pro文件,以及.pri .prj .prl文件说明
- Linux下svn文件提交后自动同步更新到网站目录
- 通过VirtualQuery查询当前进程虚拟内存使用情况
- Verilog HDL常用综合语法
- yum安装与卸载软件常见命令
- 真不敢相信!SEO优化的精髓都是这些基础!
- 文本框输入值调用回车事件
- 异步和单线程
- C++批量隔行筛选标签txt文件
- 公司没大牛带,需要离职么?
- Spring(配置文件)