C # Call thunder 7 to download the open engine

Source: Internet
Author: User

A recent project needs to use winform to call thunder for download. After surfing the Internet, Baidu finds that the com component provided by thunder has been used up since thunder 5. In addition to adding tasks, all other functions are unavailable.
Using System. Linq;
Using System. Text;
Using System. Runtime. InteropServices;
Namespace WindowsFormsApplication1
{
Class thunder
{
// Download the open engine
[DllImport ("XLDownload. dll", EntryPoint = "XLInitDownloadEngine")]
Public static extern bool XLInitDownloadEngine ();
[DllImport ("XLDownload. dll", EntryPoint = "XLUninitDownloadEngine")]
Public static extern bool XLUninitDownloadEngine ();
[DllImport ("XLDownload. dll", EntryPoint = "XLURLDownloadToFile", CharSet = CharSet. Auto)]
Public static extern int XLURLDownloadToFile (string pszFileName, string pszUrl, string pszRefUrl, ref Int32 lTaskId );
[DllImport ("XLDownload. dll", EntryPoint = "XLQueryTaskInfo", CharSet = CharSet. Auto)]
Public static extern int XLQueryTaskInfo (int lTaskId, ref int plStatus, ref UInt64 pullFileSize, ref UInt64 pullRecvSize );
[DllImport ("XLDownload. dll", EntryPoint = "XLGetErrorMsg", CharSet = CharSet. Auto)]
Public static extern int XLGetErrorMsg (int dwErrorId, string pszBuffer, ref int dwSize );
[DllImport ("XLDownload. dll", EntryPoint = "XLContinueTask", CharSet = CharSet. Auto)]
Public static extern int XLContinueTask (int lTaskId );
[DllImport ("XLDownload. dll", EntryPoint = "XLContinueTaskFromTdFile", CharSet = CharSet. Auto)]
Public static extern int XLContinueTaskFromTdFile (string pszTdFileFullPath, ref int lTaskId );
[DllImport ("XLDownload. dll", EntryPoint = "XLPauseTask", CharSet = CharSet. Auto)]
Public static extern int XLPauseTask (int lTaskId, ref int lNewTaskId );
[DllImport ("XLDownload. dll", EntryPoint = "XLStopTask", CharSet = CharSet. Auto)]
Public static extern int XLStopTask (int lTaskId );

Public const int TaskStatus_Connect = 0; // a connection has been established.
Public const int TaskStatus_Download = 2; // start download
Public const int TaskStatus_Pause = 10; // pause
Public const int TaskStatus_Success = 11; // download successful
Public const int TaskStatus_Fail = 12; // download failed


Public const int XL_SUCCESS = 0;
Public const int XL_ERROR_FAIL = 0x10000000;
 
// Initialization is not performed yet
Public const int XL_ERROR_UNINITAILIZE = XL_ERROR_FAIL + 1;
 
// Unsupported protocol. Currently, only HTTP is supported
Public const int XL_ERROR_UNSPORTED_PROTOCOL = XL_ERROR_FAIL + 2;
 
// Failed to initialize the tray icon
Public const int XL_ERROR_INIT_TASK_TRAY_ICON_FAIL = XL_ERROR_FAIL + 3;
 
// Failed to add tray icon
Public const int XL_ERROR_ADD_TASK_TRAY_ICON_FAIL = XL_ERROR_FAIL + 4;
 
// The pointer is null.
Public const int XL_ERROR_POINTER_IS_NULL = XL_ERROR_FAIL + 5;
 
// The string is an empty string
Public const int XL_ERROR_STRING_IS_EMPTY = XL_ERROR_FAIL + 6;
 
// The input path does not contain the file name
Public const int XL_ERROR_PATH_DONT_INCLUDE_FILENAME = XL_ERROR_FAIL + 7;
 
// Failed to create directory
Public const int XL_ERROR_CREATE_DIRECTORY_FAIL = XL_ERROR_FAIL + 8;
 
// Insufficient memory
Public const int XL_ERROR_MEMORY_ISNT_ENOUGH = XL_ERROR_FAIL + 9;
 
// The parameter is invalid.
Public const int XL_ERROR_INVALID_ARG = XL_ERROR_FAIL + 10;
 
// The task does not exist.
Public const int XL_ERROR_TASK_DONT_EXIST = XL_ERROR_FAIL + 11;
 
// Invalid file name
Public const int XL_ERROR_FILE_NAME_INVALID = XL_ERROR_FAIL + 12;
 
// Not implemented
Public const int XL_ERROR_NOTIMPL = XL_ERROR_FAIL + 13;
 
// The maximum number of tasks has been created, and the task cannot be created.
Public const int XL_ERROR_TASKNUM_EXCEED_MAXNUM = XL_ERROR_FAIL + 14;
 
// Unknown Task Type
Public const int XL_ERROR_INVALID_TASK_TYPE = XL_ERROR_FAIL + 15;
 
// The file already exists.
Public const int XL_ERROR_FILE_ALREADY_EXIST = XL_ERROR_FAIL + 16;
 
// The file does not exist.
Public const int XL_ERROR_FILE_DONT_EXIST = XL_ERROR_FAIL + 17;
 
// Failed to read the cfg file
Public const int xl_error_read_pai_file_fail = XL_ERROR_FAIL + 18;
 
// Failed to write the cfg file
Public const int xl_error_write_pai_file_fail = XL_ERROR_FAIL + 19;
 
// The task cannot be resumed. resumable upload is not supported, or the task has failed.
// Query the task status to identify the cause of the error.
Public const int XL_ERROR_CANNOT_CONTINUE_TASK = XL_ERROR_FAIL + 20;
 
// The task cannot be paused. resumable upload is not supported, or the task has failed.
// Query the task status to identify the cause of the error.
Public const int XL_ERROR_CANNOT_PAUSE_TASK = XL_ERROR_FAIL + 21;
 
// The buffer is too small.
Public const int XL_ERROR_BUFFER_TOO_SMALL = XL_ERROR_FAIL + 22;
 
// The thread that calls the XLInitDownloadEngine has ended before calling the XLUninitDownloadEngine.
// Initialize the Download Engine thread. It must be in the running state before calling the XLUninitDownloadEngine.
Public const int XL_ERROR_INIT_THREAD_EXIT_TOO_EARLY = XL_ERROR_FAIL + 23;
 
// TP crash
Public const int XL_ERROR_TP_CRASH = XL_ERROR_FAIL + 24;
 
// The task is invalid. You can call XLContinueTaskFromTdFile to continue the task. This error occurs when an internal task fails to be switched.
Public const int XL_ERROR_TASK_INVALID = XL_ERROR_FAIL + 25;
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.