Windows API 之 GetModuleHandle
Retrieves a module handle for the specified module. The module must have been loaded by the calling process.
HMODULE WINAPI GetModuleHandle(
_In_opt_ LPCTSTR lpModuleName
);
Parameters
- lpModuleName [in, optional]
-
The name of the loaded module (either a .dll or .exe file). If the file name extension is omitted, the default library extension .dll is appended. The file name string can include a trailing point character (.) to indicate that the module name has no extension. The string does not have to specify a path. When specifying a path, be sure to use backslashes (\), not forward slashes (/). The name is compared (case independently) to the names of modules currently mapped into the address space of the calling process.
If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process (.exe file).
Return value
If the function succeeds, the return value is a handle to the specified module.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
Remarks
The returned handle is not global or inheritable. It cannot be duplicated or used by another process.
The GetModuleHandle function returns a handle to a mapped module without incrementing its reference count. However, if this handle is passed to the FreeLibrary function, the reference count of the mapped module will be decremented. Therefore, do not pass a handle returned by GetModuleHandle to the FreeLibrary function. Doing so can cause a DLL module to be unmapped prematurely.
例如:
GetModuleHandle(NULL); // 这将返回自身应用程序句柄
GetModuleHandle("kernel32");//这将返回kernel32.dll的句柄
模块句柄实际上就是模块在当前进程空间的装入地址。即,进程地址空间中可执行文件的基址。例如:
#include <windows.h>
#include <iostream> using namespace std; int main()
{
HMODULE hModule = GetModuleHandle(NULL);
PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule;
cout << (char*)pDosHeader << endl;
system("pause");
return ;
}
输出结果:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALUAAAAtCAIAAABnBL3QAAAGq0lEQVR4nO2caVcaSRSG+R/5kA85J7M6xkQCroiiiIj7hmtQURHZGmh2E+ePzBLjhuK+C7Tb/K750NApqrtvF0yig9Z73uOB6tu3lvsARSOofGwctZeNYfYECx2IegJRbzDmDcZ8bNzLxn2hBBNKMOFlf+SjP7IciH4MRD+xsRU29ikUWwnFV8Lx30OJr2bjK2IHY594B6IfUfsjy0wYcSjBhBK+UCI3WmRIbn/U5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tVM9ZaHXvjA+sOcJDI7HGzLVAwq9MArzIYjy8YyEXjXH9h/ilxXxXaonLvTzjiy4P1VROJ6h0A/biuWDsvL0JcChyAd9oXmOcufhIOQD2LdSPUEV8nFHr59SFUiAw+WPUD6ocPFk8KZ8UOES4HD5I9lrBT7gDYf4qOIGRTKAZFtTWmb4ULGDKXnw5aSvfDBhgY+iVhA+WtQpwM5XcncMxxc1TrSdI3sP/5z4YMIoHyrRpy0ll4SEDyCnYjag2EJC7IZkX3JMKMKEdUc+l/IQ+g/iknygIim2ihgp8mLLxQDxiuWHA9C5wAkVJ1XeQr49EJbbf8CVFreTP+bgAKB3mD/JzCTx6PjFfyXHqTip8pbbH3ETv3+BJy9eSngdCfkoQTCvWCOMlyJq4hZxwjKWR3R9TLxYhPMvqt4l8FHUMCRrDBdPccpFjZYkoAwkd32shLkJi6hYSMUwoPCS/QKN4lRwPHAb7lQ8O8kTy0wCHAAfhA8moJySt4EllhQ5RuJDnBSRcv0CbMHjfFJk8OK/5sob4AM7S0yPOAzOoJiWJJ4kuXhsijzJ/ZWMV8xf3hJ/fsu3wyuiWG+AFaBRkQ85AcmF+gEnikcrPqRIgFy28hYhH9hZJPWWfGzBSQhXliSsWFgJz5WLVwQXQBnO+Z3iSSX8/7okH8CDT3KIhI1yh2CSikIWGz9hLyQdYfFAv4rBgL5fvGQ1ZU8U4BDzIZxDWEi5MLjqimkl80jexhoBRLDk2AIpgii3oIRgPa6K48PLxjzBKG+S/ankcgON4tvis+ARA5gCAZJIKXYBRALxco2yi/6ogqeGS+75A8sI3BU3Svb3TZavuLk9lOTG8OgDk1Rxa+hl49j3Kx90sFT/c9Hfh6GChP5UHH3+oMLl438uMpTwsnH6/EGFC/1d0WvKBxUmJpzg7QvFKR9UuPzhZX94mUfk+u4fygdVgfyRZcE3lA8qTOiPnVM+qDD9Cwh0ZHaPKz6jAAAAAElFTkSuQmCC" alt="" />
可以看出hModule实际上就是装入内存的PE结构的首地址(指向字符“MZ”)。
参考:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms683199%28v=vs.85%29.aspx
http://blog.csdn.net/guzhou_diaoke/article/details/8826558
Windows API 之 GetModuleHandle的更多相关文章
- Windows API 函数列表 附帮助手册
所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...
- 逆向实用干货分享,Hook技术第一讲,之Hook Windows API
逆向实用干货分享,Hook技术第一讲,之Hook Windows API 作者:IBinary出处:http://www.cnblogs.com/iBinary/版权所有,欢迎保留原文链接进行转载:) ...
- Windows API Finishing
input { font-size: 14px; height: 26px } td { border-style: none; border-color: inherit; border-width ...
- Qt 事件系统浅析 (用 Windows API 描述,分析了QCoreApplication::exec()和QEventLoop::exec的源码)(比起新号槽,事件机制是更高级的抽象,拥有更多特性,比如 accept/ignore,filter,还是实现状态机等高级 API 的基础)
事件系统在 Qt 中扮演了十分重要的角色,不仅 GUI 的方方面面需要使用到事件系统,Signals/Slots 技术也离不开事件系统(多线程间).我们本文中暂且不描述 GUI 中的一些特殊情况,来说 ...
- Windows API函数大全(完整)
Windows API函数大全,从事软件开发的朋友可以参考下 1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一 ...
- [windows菜鸟]Windows API函数大全(完整)
Windows API函数大全,从事软件开发的朋友可以参考下 1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一 ...
- WINDOWS API 大全(二)
9. API之设备场景函数 CombineRgn 将两个区域组合为一个新区域CombineTransform 驱动世界转换.它相当于依顺序进行两次转换CreateCompatibleDC 创建一个与特 ...
- Windows API 学习
Windows API学习 以下都是我个人一些理解,笔者不太了解windows开发,如有错误请告知,非常感谢,一切以microsoft官方文档为准. https://docs.microsoft.co ...
- C# Windows API
API:应用程序接口(API:Application Program Interface)应用程序接口(API:application programming interface)是一组定义.程序及协 ...
随机推荐
- LeetCode #3. Longest Substring Without Repeating Characters C#
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- Framebuffer原理、使用、测试系列文章,非常好的资料,大家一起学习
转载:http://blog.csdn.net/tju355/article/details/6881372 *一.FrameBuffer的原理* FrameBuffer 是出现在 2.2.xx 内核 ...
- react总结
在我的工作用到的最多就是backbone,其次还会有ember/Ext,backbone目前能实现我们team所需要实现的功能,因为我们的component不需要频繁的操作Dom,当后台API返回数据 ...
- C#语言之“String.Split”的使用【转】
String.Split 方法有6个重载函数: 1) public string[] Split(params char[] separator) 2) public string[] Split(c ...
- js一些小知识点
1.isNaN(),里面传一个参数,用来判断传入的值是否是数字.可以用来做一些简单的表单判断. 2.用innerHTML属性可以操作(包括获取和设置)span的内容,实际上对所有非表单元素都可以用in ...
- 微信小程序跳转页面
小程序页面有2种跳转,可以在wxml页面或者js中: 1,在wxml页面中: <navigator url="../index/index">跳转到新页面</na ...
- hdu1008
//c++// #includeusing namespace std;int main(){int n,j,t,start;while (cin >> n,n){start =0;t = ...
- Chapter 2 Open Book——30
I looked down. His hands were clenched into hard fists again. 我向下看,他的双手又一次收紧握成拳头. Mr. Banner came to ...
- java 读取excel 将数据插入到数据库
import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.sql.Con ...
- MySQL(1) - 基础
参考资料: http://www.jianshu.com/p/91e3af27743f 一.MySQL介绍以及安装 1.1 MySQL介绍 MariaDB数据库管理系统是MySQL的一个分支,主要由开 ...