C++大神求助!关于获取执行文件的路径
我今天写了个项目得获取执行文件的路径,注意:我是要在开机的时候获取某执行文件的路径,例如开机启动QQ然后获取QQ所在的文件路径GetCurrentDirectoryget...
我今天写了个项目得获取执行文件的路径,
注意:我是要在开机的时候获取某执行文件的路径,例如开机启动QQ 然后获取QQ所在的文件路径
GetCurrentDirectory
getcwd 这两个都获取不正确! 我是想在开机的时候获取 展开
注意:我是要在开机的时候获取某执行文件的路径,例如开机启动QQ 然后获取QQ所在的文件路径
GetCurrentDirectory
getcwd 这两个都获取不正确! 我是想在开机的时候获取 展开
2个回答
展开全部
因为你是获取的别的程序的路径,开机不开机时的获取结果有什么不同吗?
方案可以读取注册表获取QQ路径,还可以枚举进程获取路径。
方案可以读取注册表获取QQ路径,还可以枚举进程获取路径。
更多追问追答
追问
我上面的两个函数电脑开机后,手动运行程序,能找到对的路径。但是你让他开机自动去获取的话,那两个函数默认是获取C:\Documents and Settings\Administrator
追答
那两个函数本来就不是读取程序的路径的,是读取当前路径的。
你要获取你这个程序本身的路径,可以用 GetModuleFileName 函数,但要获得别的程序路径,只能用我说的那两种方案了。
CString _AppPath;
TCHAR sDrive[_MAX_DRIVE];
TCHAR sDir[_MAX_DIR];
TCHAR sFilename[_MAX_FNAME],Filename[_MAX_FNAME];
TCHAR sExt[_MAX_EXT];
GetModuleFileName(AfxGetInstanceHandle(), Filename, _MAX_PATH);
_tsplitpath(Filename, sDrive, sDir, sFilename, sExt);
_AppPath =(CString(sDrive) + CString(sDir));
if(_AppPath.GetAt(_AppPath.GetLength()-1) != _T('\\'))
_AppPath += _T('\\');
2013-05-10 · 知道合伙人软件行家
关注
展开全部
GetModuleFileName
该函数获取包含指定模块的可执行文件文件的全路径和文件名.
TheGetModuleFileNamefunction retrieves the full path and filename
for the executable file containing the specified module.
Windows 95:TheGetModuleFilenamefunction 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(
HMODULEhModule,// handle to module to find filename forLPTSTRlpFilename,// pointer to buffer to receive module pathDWORDnSize// size of buffer, in characters);
Parameters
hModule Handle to the module whose executable filename is being requested. If this
parameter is NULL,GetModuleFileNamereturns 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 thelpFilenamebuffer. If the
length of the path and filename exceeds this limit, the string is truncated.
Return Values
If the function succeeds, the return value is the length, in characters, of
the string copied to the buffer.
If the function fails, the return value is zero. To get extended error
information, callGetLastError.
该函数获取包含指定模块的可执行文件文件的全路径和文件名.
TheGetModuleFileNamefunction retrieves the full path and filename
for the executable file containing the specified module.
Windows 95:TheGetModuleFilenamefunction 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(
HMODULEhModule,// handle to module to find filename forLPTSTRlpFilename,// pointer to buffer to receive module pathDWORDnSize// size of buffer, in characters);
Parameters
hModule Handle to the module whose executable filename is being requested. If this
parameter is NULL,GetModuleFileNamereturns 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 thelpFilenamebuffer. If the
length of the path and filename exceeds this limit, the string is truncated.
Return Values
If the function succeeds, the return value is the length, in characters, of
the string copied to the buffer.
If the function fails, the return value is zero. To get extended error
information, callGetLastError.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询