GetModuleFileName的确可以 GetModuleFileName The GetModuleFileName function retrieves the fully qualified path for the specified module. To specify the process that contains the module, use the GetModuleFileNameEx function. DWORD GetModuleFileName( HMODULE hModule, // handle to module LPTSTR lpFilename, // path buffer DWORD nSize // size of buffer ); Parameters hModule [in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module.
GetModuleFileName
The GetModuleFileName function retrieves the fully qualified path for the specified module. To specify the process that contains the module, use the GetModuleFileNameEx function. DWORD GetModuleFileName(
HMODULE hModule, // handle to module
LPTSTR lpFilename, // path buffer
DWORD nSize // size of buffer
);
Parameters
hModule
[in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module.
#include < windows.h >
#include < string.h > HINSTANCE hInst;
char szBuf[256];
char *p; //拿到全部路径
GetModuleFileName(hInst,szBuf,sizeof(szBuf)); //分离路径和文件名。
p = szBuf;
while(strchr(p,'\\')) {
p = strchr(p,'\\');
p++;
}
*p = '\0';
//路径在szBuf理了。