Quote Originally Posted by VanGoghGaming View Post
Just updated this project following Franky's idea to download the image using WinRT methods. Now it includes a cDownloader class to encapsulate this functionality. Downloading is done asynchronously and the class raises an event when completed. The JPG image above is no longer included in the ZIP archive and instead it's downloaded on demand if it doesn't exist:

Added to Form_Load
Code:
    If Not FileExists(App.Path, "Canyon.jpg") Then
        cmdShowToastNotification.Enabled = False: Set Downloader = New cDownloader
        With Downloader
            .Uri = "https://picsum.photos/360/202?image=883"
            .StartDownloadAsync
        End With
    End If
In addition to saving data to a file, the event also exposes a buffer object with the downloaded data as well its content type so it can be used separately for downloading anything else (not specific to this project). This code snippet shows how to process the contents of the downloaded buffer:

Code:
Private Function AsIBufferByteAccess(IBufferByteAccess As IBufferByteAccess) As IBufferByteAccess
    Set AsIBufferByteAccess = IBufferByteAccess
End Function

Private Sub Downloader_DownloadCompleted(ContentType As String, DataBuffer As IBuffer)
Dim baData() As Byte ' Here we can process the contents of the downloaded buffer if desired
    ReDim baData(0 To DataBuffer.Length - 1): vbaCopyBytes DataBuffer.Length, ByVal VarPtr(baData(0)), ByVal AsIBufferByteAccess(DataBuffer).Buffer
    Downloader.SaveToFile App.Path, "Canyon.jpg"
    cmdShowToastNotification.Enabled = True ' The image download is completed so we can show the notification
    #If bInIDE Then
        Debug.Print "ContentType", ContentType, "Bytes downloaded", DataBuffer.Length
    #End If
End Sub
Thanks work perfect