libloaderapi GetModuleFileNameW

一 简介

1 原型

DWORD GetModuleFileNameW(
HMODULE hModule,
LPWSTR  lpFilename,
DWORD   nSize
);

GetModuleFileNameW
获取当前进程已加载模块的文件的完整路径,该模块必须由当前进程加载。
如果想要获取其他进程已加载模块的文件路径,可以使用GetModuleFileNameEx函数。 

2 参数

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.

一个模块的句柄。可以是一个DLL模块,或者是一个应用程序的实例句柄。如果该参数为NULL,该函数返回该应用程序全路径。

lpFilename:

A pointer to a buffer that receives the fully qualified path of the module.If the length of the path is less than the size that the nSize parameter specifies,the function succeeds and the path is returned as a null-terminated string.

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 including the terminating null character.

nSize:

The size of the lpFilename buffer, in TCHARs.

3 返回值

If the function succeeds, the return value is the length of the string that is copied to the buffer,in characters, not including the terminating null character.

If the buffer is too small to hold the module name, the string is truncated to nSize characters including the terminating null character, the function returns nSize,and the function sets the last error to ERROR_INSUFFICIENT_BUFFER.

二 举例

#include <Windows.h>
#include <iostream>
#include <string>

int main() {

  wchar_t szExeFile[MAX_PATH];
  GetModuleFileNameW(NULL, szExeFile, MAX_PATH);
  std::wstring path(szExeFile);

  getchar();
  return 0;
}

 szExeFile: L"F:\\Demo\\cppDemo\\Debug\\cppDemo.exe"

三 参考

GetModuleFileNameW

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值