Local cache of web images

I am writing a gadget to view daily comics. I would like to save the images to a local folder. Does anybody have any suggestions My gadget will display the comics I just need advice on how to save the images.

Thanks.



Answer this question

Local cache of web images

  • stallion_alpa

    The only way to do it, is code your own ActiveX DLL or an EXE and use the URLDownloadToFile API function. In VB98, that would be something like:

    Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

    Public Function DownloadFile(ByRef url As String, ByRef filename As String) As Boolean
    If URLDownloadToFile(0, url, filename, 0, 0) = 0
    DownloadFile = True
    End If
    End Function

    If that's not an option, there are some free utils that will do it, such as AutoHotKeys and use the URLDownloadToFile function. Or, AutoIt and use the InetGet function.

    With AutoIt, you'll be able to compile your own EXE which you can bundle with your gadget. The AutoIt script would be:

    #NoTrayIcon

    If $CmdLine[0]<2 or $CmdLine[1]="/ " Then
    MsgBox(0, "SaveFile", "Usage: SaveFile <URL> <filename>")
    Exit
    EndIf

    InetGet($CmdLine[1], $CmdLine[2])

  • MillaT

    Thanks for the info. I would like to try to create the ActiveX control but am having some difficulty. I keep getting the message that regsvr cannot find the entry point to DLLRegisterServer. Can these controls be created with VS2005
  • BlackMan890

    Thank you for your assistance. I found a good article by Bruce Williams referenced on this site on how to create controls using C++. I emailed him to ask if it is possible to use VB and he responded:

    You should be able to register your VB class as an ActiveX control (using the REGASM.EXE tool for example), after which you can access it from your gadget as I describe in the article.

    I followed his advice and it worked like a charm!


  • Cheryl Hu

    VS2005 won't create the DLLRegisterServer entry point - it's .NET

    So long as you've created it as an Interop Class, and it's COM Visible, you should be okay. eg:
    <System.Runtime.InteropServices.ProgId("[ProgID]")> Public Class [ClassId]

    and in the AssemblyInfo
    <Assembly: ComVisibleAttribute(True)>


    How I find out the registry entries, is somewhat of a botch. Run Process Monitor whilst you're compiling the DLL, and watch just registry writes. There will five main keys that you need to extract:

    HKLM\Software\Classes\CLSID\<CLSID>
    HKLM\Software\Classes\<ProgID>
    HKLM\Software\Component Categories\<Com GUID>
    HKLM\Software\TypeLib\<Type GUID>
    HKLM\Software\Interface\<Intergace GUID>

    To register them within your Gadget, you need to first try putting them under HKCU, then try to create your COM. If it fails, put the keys under HKLM and try to create your COM. You need to do this because for some odd reason, COM's don't work in HKCU if you're running as an elevated Administrator on Vista.

  • Ultrawhack

    I'd forgotten about REGASM! Been a few years since I've touched .NET. Ah, the problems I had trying to distribute assemblies through MSI packages - it's all flooding back!

    You can use it to get the registry keys:
    regasm.exe <file.dll> /regfile:myreg.reg

    I wouldn't use it in your Gadget though, as it requires privilages that a "User" doesn't have.

  • Local cache of web images