EDN Admin
Well-known member
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)<br/>
{<br/>
<span style="white-spacere BSTR source = ::SysAllocString(zipFile); <br/>
<span style="white-spacere BSTR dest = ::SysAllocString(unzipPath);<br/>
<br/>
<span style="white-spacere HRESULT hResult;<br/>
<span style="white-spacere IShellDispatch *pISD;<br/>
<span style="white-spacere Folder *pToFolder = NULL;<br/>
<span style="white-spacere VARIANT vDir, vFile, vOpt;<br/>
<br/>
<span style="white-spacere CoInitialize(NULL);<br/>
<br/>
<span style="white-spacere hResult = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&pISD);<br/>
<span style="white-spacere if (hResult == S_OK)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere VariantInit(&vDir);<br/>
<span style="white-spacere vDir.vt = VT_BSTR;<br/>
<span style="white-spacere vDir.bstrVal = dest;<br/>
<span style="white-spacere hResult = pISD->NameSpace(vDir, &pToFolder);<br/>
<br/>
<span style="white-spacere if (hResult == S_OK)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere Folder *pFromFolder = NULL;<br/>
<br/>
<span style="white-spacere VariantInit(&vFile);<br/>
<span style="white-spacere vFile.vt = VT_BSTR;<br/>
<span style="white-spacere vFile.bstrVal = source;<br/>
<span style="white-spacere pISD->NameSpace(vFile, &pFromFolder);<br/>
<span style="white-spacere FolderItems *fi = NULL;<br/>
<span style="white-spacere pFromFolder->Items(&fi);<br/>
<span style="white-spacere <span style="white-spacere <br/>
<br/>
<span style="white-spacere VariantInit(&vOpt);<br/>
<span style="white-spacere vOpt.vt = VT_I4;<br/>
<span style="white-spacere vOpt.lVal = FOF_NO_UI;//4; // Do not display a progress dialog box<br/>
<br/>
<span style="white-spacere <br/>
<span style="white-spacere VARIANT newV;<br/>
<span style="white-spacere VariantInit(&newV);<br/>
<span style="white-spacere newV.vt = VT_DISPATCH;<br/>
<span style="white-spacere newV.pdispVal = fi;<br/>
<span style="white-spacere hResult = pToFolder->CopyHere(newV, vOpt);<br/>
<span style="white-spacere pToFolder->Release();<br/>
<span style="white-spacere pFromFolder->Release();<br/>
<span style="white-spacere }<br/>
<span style="white-spacere pISD->Release();<br/>
<span style="white-spacere }<br/>
<span style="white-spacere SysFreeString( source);<br/>
<span style="white-spacere SysFreeString( dest);<br/>
<span style="white-spacere CoUninitialize();<br/>
<br/>
}
Could you advise me what is the root cause? And how can I fix it?
Thanks.
View the full article
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)<br/>
{<br/>
<span style="white-spacere BSTR source = ::SysAllocString(zipFile); <br/>
<span style="white-spacere BSTR dest = ::SysAllocString(unzipPath);<br/>
<br/>
<span style="white-spacere HRESULT hResult;<br/>
<span style="white-spacere IShellDispatch *pISD;<br/>
<span style="white-spacere Folder *pToFolder = NULL;<br/>
<span style="white-spacere VARIANT vDir, vFile, vOpt;<br/>
<br/>
<span style="white-spacere CoInitialize(NULL);<br/>
<br/>
<span style="white-spacere hResult = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&pISD);<br/>
<span style="white-spacere if (hResult == S_OK)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere VariantInit(&vDir);<br/>
<span style="white-spacere vDir.vt = VT_BSTR;<br/>
<span style="white-spacere vDir.bstrVal = dest;<br/>
<span style="white-spacere hResult = pISD->NameSpace(vDir, &pToFolder);<br/>
<br/>
<span style="white-spacere if (hResult == S_OK)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere Folder *pFromFolder = NULL;<br/>
<br/>
<span style="white-spacere VariantInit(&vFile);<br/>
<span style="white-spacere vFile.vt = VT_BSTR;<br/>
<span style="white-spacere vFile.bstrVal = source;<br/>
<span style="white-spacere pISD->NameSpace(vFile, &pFromFolder);<br/>
<span style="white-spacere FolderItems *fi = NULL;<br/>
<span style="white-spacere pFromFolder->Items(&fi);<br/>
<span style="white-spacere <span style="white-spacere <br/>
<br/>
<span style="white-spacere VariantInit(&vOpt);<br/>
<span style="white-spacere vOpt.vt = VT_I4;<br/>
<span style="white-spacere vOpt.lVal = FOF_NO_UI;//4; // Do not display a progress dialog box<br/>
<br/>
<span style="white-spacere <br/>
<span style="white-spacere VARIANT newV;<br/>
<span style="white-spacere VariantInit(&newV);<br/>
<span style="white-spacere newV.vt = VT_DISPATCH;<br/>
<span style="white-spacere newV.pdispVal = fi;<br/>
<span style="white-spacere hResult = pToFolder->CopyHere(newV, vOpt);<br/>
<span style="white-spacere pToFolder->Release();<br/>
<span style="white-spacere pFromFolder->Release();<br/>
<span style="white-spacere }<br/>
<span style="white-spacere pISD->Release();<br/>
<span style="white-spacere }<br/>
<span style="white-spacere SysFreeString( source);<br/>
<span style="white-spacere SysFreeString( dest);<br/>
<span style="white-spacere CoUninitialize();<br/>
<br/>
}
Could you advise me what is the root cause? And how can I fix it?
Thanks.
View the full article