获取进程中指定模块的文件路径

获取进程中指定模块的文件路径

  • 获取当前进程可执行文件的路径
#include 
void GetExeModulePath(char* lpszExePath, int iPathLen)
{
    ZeroMemory(lpszExePath, iPathLen);
    GetModuleFileNameA(NULL, lpszExePath, iPathLen);
    char *lpszSlitter = strrchr(lpszExePath, '\\');
    *(++lpszSlitter) = '\0';
}

  • 获取指定模块的文件路径
#include 
void GetDllModulePath(const char *lpszDllName, char* lpszDllPath, int iPathLen)
{
    ZeroMemory(lpszDllPath, iPathLen);
    HMODULE hDllModule = LoadLibraryA(lpszDllName);
    if (hDllModule !=  INVALID_HANDLE_VALUE)
    {
        GetModuleFileNameA(hDllModule, lpszDllPath, iPathLen);
        char *lpszSlitter = strrchr(lpszDllPath, '\\');
        *(++lpszSlitter) = '\0';
    }
}

你可能感兴趣的:(C++)