SOL9 Sample: FileDownloaderThread

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * FileDownloaderThread.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2012/04/07

#include <sol/ole/FileDownloaderThread.h>

void _tmain(int argc, TCHAR* argv[])
{
  if (argc != 3) {
    _tprintf(_T("Usage:%s url saveFileName\n"), argv[0]);
    return ;
  }
  
  const TCHAR* url = argv[1];
  const TCHAR* saveFileName = argv[2];

  try {
    //1 Create a downloader thread to download a file specified by url. 
    FileDownloaderThread* downloader = new FileDownloaderThread(url, saveFileName, GetCurrentThreadId() );
    //2 Start the downloder thread
    downloader->start();

    //3 Wait a completion of downloading thread. 
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) {
      if (msg.message == downloader->WM_FILEDOWNLOADED) {
        if (msg.wParam == TRUE) {
          _tprintf(_T("OK. Downloaded %s to %s\n"), url, saveFileName);
        }
        if (msg.wParam == FALSE) {
          _tprintf(_T("Failed to download %s to %s\n"), url, saveFileName);
        }
        break;
      }

      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }

  } catch (Exception& ex) {
    ex.printf();
  } catch (...) {

  }
}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.