VC++ 获取当前模块的路径(dll/exe)
一般地,获取当前模块路径都是通过调用 GetModuleFileName() 来获取的。
DWORD WINAPI GetModuleFileName(
__in HMODULE hModule,
__out LPTSTR lpFilename,
__in DWORD nSize
);
参数
- hModule
-
A handle to the loaded module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path of the executable file of the current process.
- lpFilename
-
A pointer to a buffer that receives the fully-qualified path of the module. If the length of the path exceeds the size that the nSize parameter specifies, the function succeeds, and the string is truncated to nSize characters and cannot be null terminated.
The string returned will use the same format that was specified when the module was loaded. Therefore, the path can be a long or short file name, and can use the prefix "\\?\". For more information, see Naming a File.
- nSize
-
The size of the lpFilename buffer, in TCHARs.
方法一: 适用于获取dll、exe路径,可在console、MFC、ATL工程中使用。
char szBuff[MAX_PATH] = {};
HMODULE hModuleInst = _AtlBaseModule.GetModuleInstance();
GetModuleFileName(hModuleInst, szBuff, MAX_PATH);方法二:适用于获取dll、exe路径,可在MFC、ATL工程中使用,不能再console中使用。
char szBuff[MAX_PATH] = {};
GetModuleFileName(AfxGetStaticModuleState()->m_hCurrentInstanceHandle, szBuff, MAX_PATH);方法三:适用于获取dll、exe路径,可在MFC、ATL工程中使用,不能再console中使用。
char szFull[_MAX_PATH] = {};
GetModuleFileName((HMODULE)&__ImageBase, szFull, _MAX_PATH);
VC++ 获取当前模块的路径(dll/exe)的更多相关文章
- VC 获取指定文件夹路径的方法小结
VC获取指定文件夹路径 flyfish 2010-3-5 一 使用Shell函数 1 获取应用程序的安装路径 TCHAR buf[_MAX_PATH];SHGetSpecialFolderPath( ...
- 获取当前模块句柄(dll、exe)
HMODULE getCurrModuleHandle(){ MEMORY_BASIC_INFORMATION info; ::VirtualQuery((LPCVOID)(&getCurrM ...
- VC获取当前程序运行路径
/***************************************************/ /* 函数: 获取当前程序运行的路径 /* 返回: 当前程序运行路径 C:\AAA\BBB\ ...
- C++获取工程路径、exe路径
编码过程中有时候会用到获取工程所在路径或者exe所在的路径信息,这里稍微记录下. 获取工程路径 char pBuf[MAX_PATH]; //存放路径的变量 GetCurrentDirectory(M ...
- Python 使用 os 模块遍历目录/获取当前文件的路径
1.列出指定目录下所包含的目录 item = os.listdir("/Users/jinchengxie/go") 返回的是一个列表, 里面包含了指定目录下所包含的所有的目录 2 ...
- python 获取导入模块的文件路径
接触到项目上有人写好的模块进行了导入,想查看模块的具体内容是如何实现的,需要找到模块的源文件. 本博文介绍两种查找模块文件路径方法: 方法一: #!/usr/bin/python # -*- codi ...
- VC档(夹)文件夹路径的经营方针和代码
***********************************************声明*************************************************** ...
- C# 获取程序运行时路径
Ø 前言 开发中,很多时候都需要获取程序运行时路径,比如:反射.文件操作等..NET Framework 已经封装了这些功能,可以很方便的使用. C# 中有很多类都可以获取程序运行时路径,我们没必要 ...
- 枚举PEB获取进程模块列表
枚举进程模块的方法有很多种,常见的有枚举PEB和内存搜索法,今天,先来看看实现起来最简单的枚举PEB实现获取进程模块列表. 首先,惯例是各种繁琐的结构体定义.需要包含 ntifs.h 和 WinDef ...
随机推荐
- MEAN组合框架搭建教程
1,我们先走在官方github里面下载个包文件: git clone https://github.com/linnovate/mean.git (是慢了点) 2,我把这个文件解压后文件名叫mean ...
- 包介绍 - Fluent Validation (用于验证)
Install-Package FluentValidation 如果你使用MVC5 可以使用下面的包 Install-Package FluentValidation.MVC5 例子: public ...
- 用GL画出人物的移动路径
注意:用Debug画的线会存在穿透问题 没啥好解释的,直接看代码: using UnityEngine; using System.Collections; using System.Collecti ...
- C#第一次的Hello World
这个Hello World是最基础的,在程序默认生成的using System下,不用自己可以的去写using System. 我们要牢记compling and running和running wi ...
- linux 模块加载
错误: rmmod 时提示 rmmod: chdir(xxx): No such file or directory 解决方法: http://blog.csdn.net/luckywang1103/ ...
- IDEA之创建不了.java文件解决
1.问题:在IDEA中新建的maven项目,无法创建.java文件 从上图看出,在new对应的栏目中没有java class选项 2.解决 这是因为maven的配置问题 应该如下: 注:如果这样还不行 ...
- nginx 虚拟主机
基于域名的虚拟主机 创建站点目录 [root@nginx conf]# cd /usr/local/nginx/html/ [root@nginx html]# pwd /usr/local/ngin ...
- Eclipse 语法提示
新建一个txt 拷贝下面的文本,然后保存修改扩展名为.epf #Sat Nov :: CST /instance/org.eclipse.jdt.core/org.eclipse.jdt.core.c ...
- API23时权限不被许可
In Android 6.0 Marshmallow, application will not be granted any permission at installation time. Ins ...
- MySQL重复数据
delete from porn where Id not in (select minid from (select min(id) as minid from porn group by view ...