C++大神求助!关于获取执行文件的路径

2024-11-01 01:34:07
推荐回答(2个)
回答1:

因为你是获取的别的程序的路径,开机不开机时的获取结果有什么不同吗?

方案可以读取注册表获取QQ路径,还可以枚举进程获取路径。

回答2:

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.