naaloh Posted March 5, 2012 Posted March 5, 2012 (edited) Hello, everyone. I'd like to use urlmon.dll (a library which is a part of Internet Explorer) for decompressing GZIP-compressed data. I've found a small piece of code (in C, I assume) that does it, however, my knowledge is currently not enough to port is to AutoIt. Whould anyone be so kind as to help? The code follows. expandcollapse popup#include <windows.h> #include <atlbase.h> #include <urlmon.h> bool UngzipFile(const char* pszInFile, const char* pszOutFile) { //create decoding object instance CComPtr pEFF; HRESULT hr = pEFF.CoCreateInstance(CLSID_StdEncodingFilterFac); CComPtr pDF; //accquire suitable filter if (!pEFF || FAILED(pEFF->GetDefaultFilter(L”gzip”, L”text”, &pDF))) { return false; } //open input gzip file HANDLE hInFile = CreateFile(pszInFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hInFile == INVALID_HANDLE_VALUE) { return false; } //create output file HANDLE hOutFile = CreateFile(pszOutFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); if (hOutFile == INVALID_HANDLE_VALUE) { CloseHandle(hInFile); return false; } //truncate out file if exist SetEndOfFile(hOutFile); unsigned long uFilePtr = 0, uLenHi, uLenLo = GetFileSize(hInFile, &uLenHi); //temporary in/out buffers BYTE inBuff[1024],outBuff[16384]; while (uFilePtr < uLenLo) { SetFilePointer(hInFile,uFilePtr,NULL,FILE_BEGIN); DWORD dwInBuffSize, dwOutBuffSize = sizeof(outBuff); ReadFile(hInFile, (VOID*)inBuff, sizeof(inBuff), &dwInBuffSize, NULL); long dwRead = 0,dwWritten = 0; //decode chunk of data hr = pDF->DoDecode(0, dwInBuffSize, (BYTE*)inBuff, dwOutBuffSize, (BYTE*)outBuff, dwInBuffSize, &dwRead, &dwWritten, 0); // increment file position with size of actually // decoded data and write decoded chunk uFilePtr+=dwRead; ULONG dwFileWritten; WriteFile(hOutFile, (VOID*)outBuff, dwWritten, &dwFileWritten, NULL); } //close in/out file handles CloseHandle(hOutFile); CloseHandle(hInFile); return true; } Thanks in advance. Edited March 5, 2012 by naaloh
guinness Posted March 5, 2012 Posted March 5, 2012 Why not use 7-Zip and this wrapper >> OR UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
KaFu Posted March 5, 2012 Posted March 5, 2012 I think Wards excellent should fit your needs. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
ProgAndy Posted March 6, 2012 Posted March 6, 2012 You will need the experimental ObjCreateInterface. Since I only have Wine here, I cannot test it:Global Const $IID_IDataFilter = "{69d14c80-c18e-11d0-a9ce-006097942311}" Global Const $vTable_IDataFilter = "DoEncode hresult(DWORD;LONG;ptr;LONG;ptr;LONG;LONG*;LONG *;DWORD); DoDecode hresult(DWORD;LONG;ptr;LONG;ptr;LONG;LONG*;LONG *;DWORD);SetEncodingLevel hresult(DWORD);" Global Const $CLSID_StdEncodingFilterFac = "{54c37cd0-d944-11d0-a9f4-006097942311}" Global Const $IID_IEncodingFilterFactory = "{70bdde00-c18e-11d0-a9ce-006097942311}" Global Const $vTable_IEncodingFilterFactory = "FindBestFilter hresult(wstr;wstr;struct;ptr*);GetDefaultFilter hresult(wstr;wstr;ptr*);" $oFilterFactory = ObjCreateInterface($CLSID_StdEncodingFilterFac, Default, $vTable_IEncodingFilterFactory) Dim $ptr $oFilterFactory.GetDefaultFilter("gzip", "text", $ptr) $oFilter = ObjCreateInterface($ptr, Default, $vTable_IDataFilter) $oFilter.DoDecode(...)Btw, you will find the vtables and IIDs when using keywords like CINTERFACE, define, UUID, MIDL_INTERFACE, ... *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
naaloh Posted March 6, 2012 Author Posted March 6, 2012 Wow, so many replies in such a short time, and much helpful replies, too. Thank you kindly, 69255 and ProgAndy, your help is much appreciated. I'll test the script by 69255 as soon as I can. The only thing that's somewhat confusing is that the description of ObjCreateInterface states "may be changed or removed without notice". Do you think there's a big chance for its removal? I'm concerned, since its removal would presumably render using urlmon.dll impossible. To answer guinness and KaFu: I would prefer not to use external libraries as long as I can make do with system ones.
ProgAndy Posted March 6, 2012 Posted March 6, 2012 The only thing that's somewhat confusing is that the description of ObjCreateInterface states "may be changed or removed without notice". Do you think there's a big chance for its removal?The functionality itself is not supposed to be removed, but the function definition (parameters) is not frozen yet and can change anytime.Could you elaborate more on this? One thing I still don't understand is how to get the CLSID, IID, and vTable. It's pretty much impossible to do anything without them.Just do a Google search and then find the correct result, e.g this *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now