日历

2008 7.27 Sun
  12345
6789101112
13141516171819
20212223242526
2728293031  
«» 2008 - 7 «»

文章搜索

日志文章

2008年03月09日 20:53:51

vc 命令行调用winrar.exe 进行文件解压

那天在写个东西的时候要先解压文件,呵呵,虽然这个算法到处都有,但是客户都使用windows操作系统,所以就想到我winrar,不就结了.余是就先查看了一下它的帮助文件,先把它在命令行下的参数搞懂 于是就开始调用,先想到的是shell .但是后来突然发现它对中文的情况支持有问题,哎,我也不晓得该怎么整,于是改了种方法.程序代码片段如下:

Copy code

int icount=m_LC.GetItemCount();
// CString cmd_str;
// cmd_str="C:\Program Files\WinRAR\WinRAR.exe";
// cmd_str=cmd_str+" e ";
// cmd_str=cmd_str+"C:\aa.zip";
// cmd_str=cmd_str+" C:\aa\";
//system(cmd_str);
//::she
m_progress.SetRange(1,icount);
for(int i=0;i<icount;i++)
{
//cmd_str=" ";
//cmd_str="c:\\Program Files\\WinRAR\\WinRAR.exe e ";
//cmd_str+=file_list.GetItemText(i,1);
//cmd_str+=" ";
//cmd_str+=Get_drection(file_list.GetItemText(i,1));
//cmd_str+="\\";
//MessageBox(cmd_str);
//::ShellExecuteEx(cmd_str);
//::system(cmd_str);
//this->m_test=cmd_str;
if(check(m_LC.GetItemText(i,1)))
{
CString str="\""+m_LC.GetItemText(i,1)+"\"";
str+=" \""+Get_drection(m_LC.GetItemText(i,1))+"\\\"";
str=get_direct()+" x -o+ -IBCK "+str;
PROCESS_INFORMATION   pidInfo;
STARTUPINFO     startInfo;
BOOL b;
char *buf=" ";
startInfo.cb           =   sizeof(STARTUPINFO);
startInfo.lpReserved   =   NULL;
startInfo.lpTitle     =   NULL;
startInfo.lpDesktop   =   NULL;
startInfo.dwX         =   0;
startInfo.dwY         =   0;
startInfo.dwXSize     =   0;
startInfo.dwYSize     =   0;
startInfo.dwXCountChars     =   0;
startInfo.dwYCountChars     =   0;
startInfo.dwFlags     =   STARTF_USESTDHANDLES;
startInfo.wShowWindow   =   0;   //SW_SHOWDEFAULT;
startInfo.lpReserved2   =   NULL;
startInfo.cbReserved2   =   0;
startInfo.hStdInput   =   GetStdHandle(STD_INPUT_HANDLE);
startInfo.hStdOutput   =   GetStdHandle(STD_OUTPUT_HANDLE);
startInfo.hStdError   =   GetStdHandle(STD_ERROR_HANDLE);  
b=CreateProcess(NULL,str.GetBuffer(0),NULL,NULL,TRUE,CREATE_NO_WINDOW,NULL,NULL,&startInfo,&pidInfo);
if(!b){
  AfxMessageBox("failed");
  return;
}
str.ReleaseBuffer();
WaitForSingleObject(pidInfo.hProcess,INFINITE);
CloseHandle(pidInfo.hProcess);
CloseHandle(pidInfo.hThread);
}
else
{
MessageBox("该文件非压缩文件哦::"+m_LC.GetItemText(i,1));
}
m_progress.SetPos(i+1);


搞定,没发现怎么问题 呵呵 : )

Tags: vc 命令行   调用winrar  

类别: C++编程 |  评论(4) |  浏览(1171) |  收藏
4楼 [匿名]小新 2008年06月16日 16:56:13 Says:
Get_drection()
get_direct()
这两个函数干什么的啊???
3楼 [匿名]小新 2008年06月16日 15:24:04 Says:
铁甲依然在:
给我发一个吧
谢谢啊
gshzyfx@163.com
2楼 [匿名]呵呵 2008年03月21日 15:51:02 Says:
或者可否发到我的邮箱:allt405415@gmail.com
呵呵,十分感谢!
1楼 [匿名]呵呵 2008年03月21日 15:50:24 Says:
又没有详细点的代码?这段代码又些地方看不到原始的函数定义看不懂啊?
发表评论