Shell32.dllを使ったZIPファイルの解凍

Shell32.dllを使ったZIPファイルの解凍(展開)処理を記載

MS非推奨のやり方なので要注意!!

bool bRet = false;

CString strOutPutPath = _T("C:\\hoge\\hoge"); // 解凍先のパスを指定
CString strZipPath = _T("C:\\huga\\huga.zip"); // 圧縮ファイルを指定

Shell32::IShellDispatchPtr pShell;
Shell32::FolderPtr pZipFile = NULL;
Shell32::FolderItemsPtr pZipItems = NULL;
Shell32::FolderPtr pOutPutDir = NULL;
do {
CoInitialize(NULL);
HRESULT hRet = S_FALSE;
hRet = pShell.CreateInstance(__uuidof(Shell32::Shell));
if ( hRet != S_OK){
break;
}
pZipFile = pShell->NameSpace( (COleVariant)strZipPath );
if(NULL == pZipFile){
break;
}
pZipItems= pZipFile->Items();
pOutPutDir= pShell->NameSpace( (COleVariant)strOutPutPath );
if( (NULL == pZipItems) || (NULL == pOutPutDir) ){
break;
}

long iOpt = FOF_SILENT | FOF_NOCONFIRMATION; // プログレスバーを表示しない 確認もなし
hRet = pOutPutDir->CopyHere(_variant_t((IDispatch*)pZipItems,true), (COleVariant)iOpt);
if(S_OK == hRet) {
bRet = true;
};
} while(FALSE);

if(pOutPutDir) {
pOutPutDir.Release();
pOutPutDir= NULL;
}
if(pZipItems) {
pZipItems.Release();
pZipItems= NULL;
}
if(pZipFile) {
pZipFile.Release();
pZipFile= NULL;
}

CoUninitialize();

return bRet;

L28のキャストに悩んだ、、、

IF分のネストが嫌だったのでdo while(false)としたけど、
無駄にステップ数増えたな、、、、

ZIPファイルの圧縮処理は以下のサイト参考
shell32.dllでファイル圧縮(VC++)

スポンサーリンク
スポンサーリンク
スポンサーリンク
  • このエントリーをはてなブックマークに追加

コメントをどうぞ

メールアドレスが公開されることはありません。