VC++实现CAB压缩解压文件_.docx

上传人:PIYPING 文档编号:11651362 上传时间:2021-08-28 格式:DOCX 页数:8 大小:13KB
返回 下载 相关 举报
VC++实现CAB压缩解压文件_.docx_第1页
第1页 / 共8页
VC++实现CAB压缩解压文件_.docx_第2页
第2页 / 共8页
VC++实现CAB压缩解压文件_.docx_第3页
第3页 / 共8页
VC++实现CAB压缩解压文件_.docx_第4页
第4页 / 共8页
VC++实现CAB压缩解压文件_.docx_第5页
第5页 / 共8页
亲,该文档总共8页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《VC++实现CAB压缩解压文件_.docx》由会员分享,可在线阅读,更多相关《VC++实现CAB压缩解压文件_.docx(8页珍藏版)》请在三一文库上搜索。

1、VC+实现CAB压缩解压文件_ C+实现CAB压缩解压文件 示例参考 / This is an ID which is written (invisible) into the CAB file UINT u32_CabID = 12345; / Store filetimes as UTC in CAB files BOOL b_StoreUtcTime = TRUE; / Change this to split the archive into multiple files (202100 - CAB split size = 200kB) / ATTENTION: In this ca

2、se Parameter 1 of CreateFCIContext MUST contain %d UINT u32_SplitSize = 0x7FFFFFFF; / You can specify your own key for CAB encryption here (the longer the more secure, up to 5000 characters) / Set empty EncryptionKey () to get a CAB file without encryption char* s8_EncryptionKey = ; /char* s8_Encryp

3、tionKey = AH%KJ/76?KJ逪謀狞dghf7(ZTbjasdf82izsx87qpc5bam;-l#; / # Initialization # char s8_WinDirMAX_PATH; GetWindowsDirectoryA(s8_WinDir, sizeof(s8_WinDir); char s8_ExplorerMAX_PATH; char s8_Notepad MAX_PATH; sprintf(s8_Explorer, %sExplorer.exe, s8_WinDir); sprintf(s8_Notepad, %sNotepad.exe, s8_WinDir

4、); char s8_WorkDirMAX_PATH; GetCurrentDirectoryA(sizeof(s8_WorkDir), s8_WorkDir); char s8_CompressDirMAX_PATH; char s8_DecryptDir MAX_PATH; char s8_ExtractDir MAX_PATH; sprintf(s8_CompressDir, %s_Compressed, s8_WorkDir); sprintf(s8_DecryptDir, %s_Decrypted, s8_WorkDir); sprintf(s8_ExtractDir, %s_Ext

5、racted, s8_WorkDir); char s8_CompressFileMAX_PATH; strcpy(s8_CompressFile, s8_CompressDir); strcat(s8_CompressFile, Packed_%d.cab); Cabinet:CCompress i_Compress; Cabinet:CExtract i_ExtrDecrypt; Cabinet:CExtractResource i_ExtrResource; i_Compress. SetEncryptionKeyA(s8_EncryptionKey); i_ExtrDecrypt.Se

6、tDecryptionKeyA(s8_EncryptionKey); #ifdef UNICODE printf(UNICODE compiledn); #else printf(MBCS compiledn); #endif / # Compress demo # / This will pack Explorer.exe and Notepad.exe into a CAB file with subfolders printf(n CAB FILE COMPRESSIONnn); if (!i_Compress.CreateFCIContextA(s8_CompressFile, b_S

7、toreUtcTime, u32_SplitSize, u32_CabID) printf(Compress ERROR: Could not create FCI context:n%sn, i_Compress.LastErrorA(); goto _RESOURCE; if (!i_Compress.AddFileA(s8_Explorer, FileManagerExplorer.exe, 0) printf(Compress ERROR: Could not add Explorer.exe to cabinet:n%sn, i_Compress.LastErrorA(); goto

8、 _RESOURCE; if (!i_Compress.AddFileA(s8_Notepad, TextManagerNotepad.exe, 0) printf(Compress ERROR: Could not add Notepad.exe to cabinet:n%sn, i_Compress.LastErrorA(); goto _RESOURCE; if (!i_Compress.FlushCabinet(FALSE) printf(Compress ERROR: Could not flush Cabinet:n%sn, i_Compress.LastErrorA(); got

9、o _RESOURCE; printf(SUCCESS: Compressed Explorer.exe and Notepad.exe into cabinet inn%sn, s8_CompressDir); / # Decrypt demo # / This will decrypt the CAB file which was encrypted above if (!s8_EncryptionKey0) / Skip the following if the file was not encrypted goto _RESOURCE; printf(n-n); printf(n CA

10、B FILE DECRYPTIONnn); if (!i_ExtrDecrypt.CreateFDIContext() printf(Decrypt ERROR: Could not create FDI context:n%sn, i_ExtrDecrypt.LastErrorA(); goto _RESOURCE; / replace %d - 1 sprintf(s8_CompressFile, s8_CompressFile, 1); / Now extract into subdirectory _Decrypted and the corresponding subdirector

11、ies in the CAB file if (!i_ExtrDecrypt.ExtractFileA(s8_CompressFile, s8_DecryptDir) printf(Decrypt ERROR: Not all files could be extracted:n%sn, i_ExtrDecrypt.LastErrorA(); goto _RESOURCE; printf(SUCCESS: Decrypted all files from the above encrypted cabinet inton%sn, s8_DecryptDir); / # Extract reso

12、urce demo # / This will extract the file Test.cab in the embedded resources into a directory _RESOURCE: printf(n-n); printf(n CAB RESOURCE EXTRACTIONnn); if (!i_ExtrResource.CreateFDIContext() printf(Extract ERROR: Could not create FDI context:n%sn, i_ExtrResource.LastErrorA(); goto _WAIT; /* / Now

13、extract into subdirectory _Extracted and the corresponding subdirectories in the CAB file if (!i_ExtrResource.ExtractResourceA(0, ID_CAB_TEST, CABFILE, s8_ExtractDir) printf(Extract ERROR: Not all files could be extracted:n%sn, i_ExtrResource.LastErrorA(); goto _WAIT; */ printf(SUCCESS: Extracted all files from cabinet resource Test.cab inton%sn, s8_ExtractDir); _WAIT: / Under some cirumstances the DOS window disappears immediately, so you cannot read anything! printf(nnHit any key to exitn); getch(); 更多信息请查看IT技术专栏 .

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1