Sunday, March 23, 2008

How do I find the path of my exe file?

You can use GetModuleFileNameEx.
DWORD WINAPI GetModuleFileNameEx(
HANDLE hProcess, // handle to a process
HMODULE hModule, // handle to a module
LPTSTR lpFilename, // receives file path
DWORD nSize // length of lpFilename
);
This will load the path of the currently running exe file into a buffer named path.
#include <psapi.h>
char path[MAXPATH];
GetModuleFileNameEx(GetCurrentProcess(), NULL, path, MAXPATH);

No comments: