DWORD GetModuleFileName( HMODULE hModule, // handle to module to find filename for LPTSTR lpFilename, // pointer to buffer to receive module path DWORD nSize // size of buffer, in characters );If hModule is NULL, GetModuleFileName returns the path for the file used to create the calling process.
VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuffer, _MAX_PATH));只要目录的话可以用
PathRemoveFileSpec
msdn上有示例
DWORD GetModuleFileName(
HMODULE hModule, // handle to module
LPTSTR lpFilename, // path buffer
DWORD nSize // size of buffer
);
如果第一个参数为NULL表示获取当前程序的可执行文件的路径!
HMODULE hModule, // handle to module to find filename for
LPTSTR lpFilename, // pointer to buffer to receive module path
DWORD nSize // size of buffer, in characters
);If hModule is NULL, GetModuleFileName returns the path for the file used to create the calling process.
GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind ('\\');
sPath=sPath.Left (nPos);//sPath中就保存了可执行文件的当前目录