|
今天做个东西的时候,突然需要这个东西,上网一查,有人就说用下面的方法,但是不是想要的结果 #include < windows.h > #include < string.h >
HINSTANCE hInst; char szBuf[256]; char *p; GetModuleFileName(hInst,szBuf,sizeof(szBuf)); p = szBuf; while(strchr(p,'\\')) { p = strchr(p,'\\'); p++; } *p = '\0';
上面的这个是获取当前选择的目录路径的,比如说常用的文件选择对话框选择路径的获取.下面的方法才是想要的.程序中我是想要获取安装在我程序的子目录下的winrar.exe的路径,就这样写,
CString get_direct() { char temp [256]; char drive[256]; char dir[256]; CString str1, str2; GetModuleFileName(NULL, temp, 256); _splitpath(temp, drive, dir, NULL, NULL ); str1 = drive; str2 = str1+dir; str2.Replace("[url=file://\\]\\","\\\\"); //此处由于我要在命令行中使用,所以要把\这个转义符搞掉 str2=str2+"Cunzip\\WinRAR.exe"; return str2; }
呵呵,问题虽小,但没用过就是不晓得哈. ) :
|
一共有 0 条评论