本文介绍了使用shell32 API解压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好, 我尝试下面的代码将文件解压缩到临时文件夹中,但是,在Win XP中,我总是看到显示的进度对话框并且有一些临时的临时文件夹中的文件夹虽然在Win 7中没有发生。我也收到了错误消息"该文件存在"。  void解压缩(LPCWSTR zipFile,LPCWSTR unzipPath) { BSTR source = :: SysAllocString(zipFile);  BSTR dest =  :: SysAllocString(unzipPath); $ HRESULT          hResult; IShellDispatch * pISD; 文件夹                * pToFolder = NULL; VARIANT          vDir,vFile,vOpt; $ CoInitialize(NULL); hResult = CoCreateInstance(CLSID_Shell,NULL,CLSCTX_INPROC_SERVER,IID_IShellDispatch,(void **)& pISD); if(hResult == S_OK) { VariantInit(& vDir); vDir.vt = VT_BSTR; vDir.bstrVal = dest; hResult = pISD-> NameSpace(vDir,& pToFolder); if(hResult == S_OK) { 文件夹* pFromFolder = NULL; VariantInit(& vFile); vFile.vt = VT_BSTR; vFile.bstrVal = source; pISD-> NameSpace(vFile,& pFromFolder); FolderItems * fi = NULL; pFromFolder-> Items(& fi); VariantInit(& vOpt); vOpt.vt = VT_I4; vOpt.lVal = FOF_NO_UI; // 4; //不显示进度对话框 VARIANT newV; VariantInit(& newV); newV.vt = VT_DISPATCH; newV.pdispVal = fi; hResult = pToFolder-> CopyHere(newV,vOpt); pToFolder-> Release(); pFromFolder-> Release(); } pISD-> Release(); } SysFreeString(source); SysFreeString(dest); CoUninitialize(); } 你能告诉我什么是根本原因?我该如何解决? 谢谢。解决方案 你好, 你发送给这个函数的路径字符串是什么? 另外,你可以试试这个帖子中的代码, http://social.msdn.microsoft.com/论坛/ en / vclanguage / thread / 45668d18-2840-4887-87e1-4085201f4103 最好的问候, Jesse Hello,I try the code below to unzip a file into temp folder, however, in Win XP, I always see the progress dialog shown and there are some temporary folder in temp folder while it does not happen in Win 7. An also I got the error message " The file exists". void Unzip(LPCWSTR zipFile, LPCWSTR unzipPath){BSTR source = ::SysAllocString(zipFile); BSTR dest =  ::SysAllocString(unzipPath);HRESULT          hResult;IShellDispatch *pISD;Folder                *pToFolder = NULL;VARIANT          vDir, vFile, vOpt;CoInitialize(NULL);hResult = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&pISD);if (hResult == S_OK){VariantInit(&vDir);vDir.vt = VT_BSTR;vDir.bstrVal = dest;hResult = pISD->NameSpace(vDir, &pToFolder);if (hResult == S_OK){Folder *pFromFolder = NULL;VariantInit(&vFile);vFile.vt = VT_BSTR;vFile.bstrVal = source;pISD->NameSpace(vFile, &pFromFolder);FolderItems *fi = NULL;pFromFolder->Items(&fi);VariantInit(&vOpt);vOpt.vt = VT_I4;vOpt.lVal = FOF_NO_UI;//4; // Do not display a progress dialog boxVARIANT newV;VariantInit(&newV);newV.vt = VT_DISPATCH;newV.pdispVal = fi;hResult = pToFolder->CopyHere(newV, vOpt);pToFolder->Release();pFromFolder->Release();}pISD->Release();}SysFreeString( source);SysFreeString( dest);CoUninitialize();}Could you advise me what is the root cause? And how can I fix it?Thanks. 解决方案 Hello,What the path string do you send to this function?In addition, you can try the codes in this thread,http://social.msdn.microsoft.com/Forums/en/vclanguage/thread/45668d18-2840-4887-87e1-4085201f4103Best regards,Jesse 这篇关于使用shell32 API解压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-13 18:03