int nDrive = _getdrive();//Get current path TCHAR szPath[_MAX_PATH]; VERIFY( _getdcwd( nDrive, szPath, _MAX_PATH ) != NULL ); szPath就是应用程序本身所在路径
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 ); The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module.
TCHAR szPath[_MAX_PATH];
VERIFY( _getdcwd( nDrive, szPath, _MAX_PATH ) != NULL );
szPath就是应用程序本身所在路径?
DWORD dwPathLen = 0;
if((dwPathLen = ::GetModuleFileName(
::AfxGetInstanceHandle(),
szFilename,
MAX_PATH
)) == 0) {
return FALSE;
}
for(int i=dwPathLen-1; i>=0; i--) {
if(('\\' == szFilename[i])
|| ('/' == szFilename[i])) {
break;
} else {
szFilename[i] = '\0';
}
}
DWORD dwPathLen = 0;
if((dwPathLen = ::GetModuleFileName(
::AfxGetInstanceHandle(),
szFilename,
MAX_PATH
)) == 0) {
return FALSE;
}
for(int i=dwPathLen-1; i>=0; i--) {
if(('\\' == szFilename[i])
|| ('/' == szFilename[i])) {
break;
} else {
szFilename[i] = '\0';
}
}
TCHAR szPath[_MAX_PATH];
VERIFY( _getdcwd( nDrive, szPath, _MAX_PATH ) != NULL );
szPath就是应用程序本身所在路径
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
);
The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module.
char lpFn[100];
// HANDLE hFile;
::GetModuleFileName(hModule,lpFn,100);