[求助]如何获得程序路径
那么我们该如何去获得程序路径呢?程序大本营上是使用的 API 函数 GetModuleFileName(),例如,我使用以下代码定位程序路径和取文件的完整路径文件名:
CString appPath;
GetModuleFileName(NULL, appPath.GetBuffer(MAX_PATH), MAX_PATH);
//注:使用该API函数得到的是程序文件完整路径文件名,去掉文件名后才是路径。
appPath.ReleaseBuffer();
int n = appPath.ReverseFind(\\);
CString helpFile;
helpFile = appPath.Left(n);
TCHAR c = helpFile.GetAt(n - 1);
if(c == \\) helpFile += "HtmlHelp.chm";
else helpFile += "\\HtmlHelp.chm";
通过 HtmlHelp 调用帮助文件(.chm)的程序代码如下:
HtmlHelp(NULL, (LPCSTR)helpFile, HH_DISPLAY_TOPIC, 0);
以上是在VC中调用HTML文件的关联程序.按照上面获取文件路径的方法我操作时出现以下错误,请大家帮我看看出了什么问题.
C:\Documents and Settings\yease\桌面\Tester(ListView)450\Demo_Outlook.cpp(1094) : error C2017: illegal escape sequence
C:\Documents and Settings\yease\桌面\Tester(ListView)450\Demo_Outlook.cpp(1094) : error C2017: illegal escape sequence
C:\Documents and Settings\yease\桌面\Tester(ListView)450\Demo_Outlook.cpp(1094) : error C2660: 'ReverseFind' : function does not take 0 parameters
C:\Documents and Settings\yease\桌面\Tester(ListView)450\Demo_Outlook.cpp(1098) : error C2017: illegal escape sequence
C:\Documents and Settings\yease\桌面\Tester(ListView)450\Demo_Outlook.cpp(1098) : error C2017: illegal escape sequence
C:\Documents and Settings\yease\桌面\Tester(ListView)450\Demo_Outlook.cpp(1098) : error C2059: syntax error : ')'
C:\Documents and Settings\yease\桌面\Tester(ListView)450\Demo_Outlook.cpp(1099) : error C2181: illegal else without matching if
Error executing cl.exe.
本人绝对的菜鸟,如果高手能给出直接可以用的程序将万分感激.