如何得到程序所在路径?
我写的一个程序,它有可能被复制到其它的路径下执行,怎么取得当前的路径呢? 问题点数:0、回复次数:13Top
1 楼isdong(有些事情应该忘记)回复于 2002-12-03 12:47:32 得分 0
GetCurrentDirectoryTop
2 楼sxxny(轻云(Srj))回复于 2002-12-03 12:48:36 得分 0
楼上的Top
3 楼liu_feng_fly(笑看风云 搏击苍穹 衔日月)回复于 2002-12-03 12:55:26 得分 0
GetModuleFileName
The GetModuleFileName function retrieves the full path and file name for the file containing the specified module.
Windows 95/98: The GetModuleFilename function retrieves long file names when an application's version number is greater than or equal to 4.00 and the long file name is available. Otherwise, it returns only 8.3 format file names.
DWORD GetModuleFileName(
HMODULE hModule, // handle to module
LPTSTR lpFilename, // file name of module
DWORD nSize // size of buffer
);
应该使用这个函数
因为GetCurrentDirectory得到的路径可以被函数
SetCurrentDirectory
The SetCurrentDirectory function changes the current directory for the current process.
BOOL SetCurrentDirectory(
LPCTSTR lpPathName // new directory name
);
改变,所以不一定正确
Top
4 楼wltsui(-无招胜有招-)回复于 2002-12-03 12:57:08 得分 0
GetModuleFileNameTop
5 楼prettywolf(多情自古空余恨,此恨绵绵无绝期)回复于 2002-12-03 12:58:07 得分 0
好像liu_feng_fly(笑看风云 搏击苍穹 衔日月) 说得有道理一点,我回去试试看.Top
6 楼JoshuaLi()回复于 2002-12-03 12:58:33 得分 0
GetModuleFileName()
The GetModuleFileName function retrieves the full path and file name for the file containing the specified module.
Top
7 楼prettywolf(多情自古空余恨,此恨绵绵无绝期)回复于 2002-12-03 12:59:11 得分 0
只不过HMODULE hModule如何得知?Top
8 楼andy_lau(天行键,君子当自强不息!)回复于 2002-12-03 13:03:24 得分 0
HMODULE其实就是hinstance
findwindow()Top
9 楼andy_lau(天行键,君子当自强不息!)回复于 2002-12-03 13:04:08 得分 0
在程序里面得到:
AfxGetApp()->m_hInstance;Top
10 楼howtotell(从何谈起)回复于 2002-12-03 13:05:11 得分 0
char szWrite[256];
strcpy(szWrite,__argv[0]);
//szWrite就是了。Top
11 楼free_card(痛并快乐着)回复于 2002-12-03 13:06:19 得分 0
TCHAR exeFullPath[MAX_PATH]; // MAX_PATH在API中定义了吧,好象是128
// tmpsql1=GetPathName( );
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
GetCurrentDirectory(127,str);
Top
12 楼yuanbocsut(井冈星火)回复于 2002-12-03 13:12:54 得分 0
upTop
13 楼zhou80bin(彬彬)回复于 2002-12-03 13:13:18 得分 0
gzTop




