我想得到当前程序的路径,用了以下代码:CString path_directory,path_txt; //path_txt已经能得到完整的路径
GetModuleFileName(NULL,path_txt.GetBuffer(100),100); //path_directory_length也得到了位置序号
int path_directory_length = path_txt.ReverseFind('\\'); //这里path_directory的内容为何一直和path_txt一样?
path_directory = path_txt.Left(path_directory_length+1); path_txt.ReleaseBuffer();
GetModuleFileName(NULL,path_txt.GetBuffer(100),100); //path_directory_length也得到了位置序号
int path_directory_length = path_txt.ReverseFind('\\'); //这里path_directory的内容为何一直和path_txt一样?
path_directory = path_txt.Left(path_directory_length+1); path_txt.ReleaseBuffer();
path_directory_length 21 int
path_txt {0x00347a30 "d:\ex\Recognise\Debug\Recognise.exe"}
path_directory {0x00347a30 "d:\ex\Recognise\Debug\Recognise.exe"}
GetModuleFileName(NULL,path_txt.GetBuffer(100),100);
改成即可:GetModuleFileName(NULL,path_txt.GetBufferSetLength(100),100);
先releasebuffer
然后取left这样是可以的,谢谢~
谢谢各位
//path_txt已经能得到完整的路径
GetModuleFileName(NULL,path_txt.GetBuffer(100),100);
改成即可:GetModuleFileName(NULL,path_txt.GetBufferSetLength(100),100);
也可以,结帖了
我要找找解释了。