这个怎么办?文件目录的问题...

gamezealot 2004-09-01 03:21:35
char strFileName[63],path[]="\\ChangePixel.exe";
::GetCurrentDirectory(64,strFileName);
strcat(strFileName,path);
AfxMessageBox(strFileName);
上面的是我的代码,我想得到程序的绝对路径,一般情况下很正常,strFileName返回的就是绝对路径。比如在D:\File\ChangePixel.exe下运行,返回就是D:\File\ChangePixel.exe。可是当我在跟目录(即盘符)下运行时就会得到比如在E:\,会得到E:\\ChangePixel.exe,这样就路径是不正确的,请问怎么解决啊?
...全文
90 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhushizu 2004-09-01
  • 打赏
  • 举报
回复
您可以到Google上搜一下呀,这方面的资料还是多的..但一定要有耐心...楼主加油了!!!!!
lixiaosan 2004-09-01
  • 打赏
  • 举报
回复
TCHAR szCurPath[MAX_PATH];
TCHAR path[MAX_PATH]="\\ChangePixel.exe";

memset(szCurPath, 0, MAX_PATH);

GetModuleFileName(NULL, szCurPath, sizeof(szCurPath)/sizeof(TCHAR));
CString str;
str = szCurPath;
str = str.Left(str.ReverseFind('\\'));
str += (CString)path;
AfxMessageBox(str);
gamezealot 2004-09-01
  • 打赏
  • 举报
回复
谢谢,明白了!
ghxmagic 2004-09-01
  • 打赏
  • 举报
回复
以下函数会返回当前可执行程序的所在路径

CString CDlgSheet::GetModulePath()
{
TCHAR tzModule[MAX_PATH];
GetModuleFileName(NULL, tzModule, sizeof(tzModule));

CString strModule(tzModule);
return strModule.Left(strModule.ReverseFind(_T('\\')));
}
gamezealot 2004-09-01
  • 打赏
  • 举报
回复
To:yening0914(大山)

GetCurrentDirectory
The GetCurrentDirectory function retrieves the current directory for the current process. //这个MSDN不是说了吗?得到当前进程的目录??

DWORD GetCurrentDirectory(
DWORD nBufferLength, // size of directory buffer
LPTSTR lpBuffer // directory buffer
);
goldenfall 2004-09-01
  • 打赏
  • 举报
回复
CHAR exeFullPath[MAX_PATH];
CString strPath;
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
strPath=(CString)exeFullPath;
int position=strPath.ReverseFind('\\');
strPath=strPath.Left(position+1);
gamezealot 2004-09-01
  • 打赏
  • 举报
回复
那你说是那个,请告诉我呀~谢谢!
yening0914 2004-09-01
  • 打赏
  • 举报
回复
GetCurrentDirectory并不是用于得到程序的目录呀!!
gamezealot 2004-09-01
  • 打赏
  • 举报
回复
我知道产生的原因,可我对函数不熟悉,所以,不知道该怎么解决,请教大家一下!

1,650

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 非技术类
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧