static char BASED_CODE szFilter[] = "SAVE FILE (*.txt)|*.txt|All Files (*.*)|*.*||";
CFileDialog dlg(TRUE,NULL,"cy.txt",OFN_HIDEREADONLY|
OFN_OVERWRITEPROMPT,szFilter,NULL);
CString m_save;
if(dlg.DoModal()==IDOK)
{
m_Save=dlg.GetPathName();
UpdateData(FALSE);
}
在上述程序中在m_save得到可执行文件的当前路径,但在VC下直接运行时得到的是
上一级命令,直接运行生成的可执行文件时却得到"C:\我的文档",请问如何直接运行生成的可执行文件时得到可执行文件所在的当前路径
CFileDialog dlg(TRUE,NULL,"cy.txt",OFN_HIDEREADONLY|
OFN_OVERWRITEPROMPT,szFilter,NULL);
CString m_save;
if(dlg.DoModal()==IDOK)
{
m_Save=dlg.GetPathName();
UpdateData(FALSE);
}
在上述程序中在m_save得到可执行文件的当前路径,但在VC下直接运行时得到的是
上一级命令,直接运行生成的可执行文件时却得到"C:\我的文档",请问如何直接运行生成的可执行文件时得到可执行文件所在的当前路径
CString sModFileName;
GetModuleFileName(NULL, sModFileName.GetBuffer(MAX_PATH), MAX_PATH);
sModFileName.ReleaseBuffer();
sModFileName.MakeReverse();
sIniFilePath = sModFileName.Right(sModFileName.GetLength() - ModFileName.Find('\\'));
sIniFilePath.MakeReverse();
//sIniFilePath就是你要得到的路径
GetModuleFileName(AfxGetInstanceHandle(),sCurrentDirectory,sizeof(sCurrentDirectory));
CString sModFileName;
GetModuleFileName(NULL, sModFileName.GetBuffer(MAX_PATH), MAX_PATH);
sModFileName.ReleaseBuffer();
sModFileName.MakeReverse();
sIniFilePath = sModFileName.Right(sModFileName.GetLength() - sModFileName.Find('\\'));
sIniFilePath.MakeReverse();
-----------------------------------
sIniFilePath就是你要得的路径
GetModuleFileName(NULL,exeFullPath,100);
The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module. Windows 95: The GetModuleFilename function will return long filenames when an application's version number is greater than or equal to 4.00 and the long filename is available. Otherwise, it returns only 8.3 format filenames.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
);
Parameters
hModule
Handle to the module whose executable filename is being requested. If this parameter is NULL, GetModuleFileName returns the path for the file used to create the calling process.
lpFilename
Pointer to a buffer that is filled in with the path and filename of the given module.
nSize
Specifies the length, in characters, of the lpFilename buffer. If the length of the path and filename exceeds this limit, the string is truncated.