獲取進程中指定模塊的文件路徑

獲取進程中指定模塊的文件路徑

  • 獲取當前進程可執行文件的路徑
#include <windows.h>
void GetExeModulePath(char* lpszExePath, int iPathLen)
{
    ZeroMemory(lpszExePath, iPathLen);
    GetModuleFileNameA(NULL, lpszExePath, iPathLen);
    char *lpszSlitter = strrchr(lpszExePath, '\\');
    *(++lpszSlitter) = '\0';
}

  • 獲取指定模塊的文件路徑
#include <windows.h>
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';
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章