Very useful operation of Internet API functions
Winnet.dll files must be installed, the function is powerful than Winsock. However, the instructions and examples in the msdn are C , and even the VB is not. I tried some functions.
First put it out for your reference.
* All functions If the run fails, return 0 successfully returns 1 or handle.
* Most of the parameters is the default, parameter specific content, check the help file.
1. Check if the Internet is connected
Declare Integer InternetGetConnectedState in "Wininet.dll" Integer, Integer
InternetGetConnectedState (0, 0)
2. Auto Dial - Use the default dial-up connection (I must set a dial-up connection in IE, there is an InternetDial function, you must use the dial-up connection name)
Declare Integer InternetAutodial in "Wininet.dll" Integer, Integer
? InternetAutodial (0, 0)
3. Automatically interrupt dial or connection
Declare Integer InternetAutodialHangup in "Wininet.dll" Integer
? InternetAutodialhangup (0)
4. Get a connection handle
Declare Integer Internetopen in "Wininet.dll" String, Integer, String, String, Integer
lnopen = Internetopen ("Myftp", 1, Null, NULL, 0)
5. Connect to FTP Server
Declare Integer InternetConnect in "WinInet.dll" Integer, String, Integer, String, String, Integer, Integer, Integer
Lnconn = InternetConnect (lnopen, "ftp.microsoft.com", 0, "anonymous", "aaaaa@yahoo.com", 1, 0, 0)
6. Download a file. There are also many FTP or HTTP operation files or functions of the page. Interested by try
Declare Integer FTPGETFILE IN "Wininet.dll" Integer, String, String, Integer, Integer, Integer, Integer
? Ftpgetfile (lnconn, '' / bussys / readme.txt '', '' c: /temp/msreadme.txt ', 0, 0, 1, 0)
7. Interrupt connection
Declare Integer InternetCloseHandle in "Wininet.dll" Integer
? InternetCloseHandle (Lnconn)
Below is most of the API functions in Wininet.dll, which is a statement in VB format:
Declare function getProcessHeap lib "kernel32" () AS Long
Declare Function Heapalloc LIB "Kernel32" (Byval HHEAP As Long, Byval dwbytes as long) AS Long
Declare Function Heapfree Lib "Kernel 32" (Byval HHEAP As Long, LPMEM AS ANY) AS LongdeClare Sub CopyMemory1 LIB "Kernel32" Alias "RTLMOVEMEMORY" (_
HPVDEST AS Any, Byval HPVSource As Long, Byval CBCopy As Long
Declare Sub CopyMemory2 LIB "kernel32" Alias "RTLMOVEMEMORY" (_
HPVDest As Long, HPVSource As Any, Byval Cbcopy As Long
Public const error_no_more_files = 18
Public Declare Function InternetFindNextFile Lib "Wininet.dll" Alias "InternetFindNextFilea" _
(Byval Hfind AS WIN32_FINDDATA AS WIN32_FIND_DATA) AS Long
Public Declare Function FTPFINDFIRSTFILE LIB "Wininet.dll" Alias "ftpfindfirstfilea" _
(Byval Hftpsession As Long, Byval Lpszsearchfile As String, _
LPFINDFILEDATA AS WIN32_FIND_DATA, BYVAL DWFLAGS As Long, BYVAL DWCONTENT AS Long AS Long
Public Declare Function FTPGETFILE LIB "Wininet.dll" Alias "ftpgetfilea" _
(Byval HFTPSession as Long, Byval Lpszremotefile As String, _
Byval lpsznewfile as string, byval ffailifexists as boolean, byval dwflagsandattributes as long, _
Byval dwflags as long, byval dwcontext as long) as boolean
Public Declare Function Ftpputfile Lib "Wininet.dll" Alias "ftpputfilea" _
(Byval HFTPSession as Long, Byval Lpszlocalfile As String, _
Byval lpszremotefile asse string, _
Byval dwflags as long, byval dwcontext as long) as boolean
Public Declare Function FTPSetCurrentDirectory Lib "Wininet.dll" Alias "ftpsetcurrentdirectorya" _
(Byval Hftpsession As Long, Byval Lpszdirectory As String) AS Boolean
Public Declare Function FTPGETCURRENTDIRECTORY LIB "Wininet.dll" Alias "ftpgetcurrentdirectorya" _
(Byval HFTPSession as stay, ByVal Lpszdirectory As String, Byref LPDWCURRENTDIRECTORY AS long) AS Boolean '' INITIZES An Application ''s Use of the Win32 Internet Functions
Public Declare Function Internetopen Lib "Wininet.dll" Alias "Internetopena" _
(Byval Sagent As String, ByVal Laccesstype As Long, Byval Sproxyname As String, _
BYVAL SPROXYBYPASS AS STRING, BYVAL LFLAGS AS Long AS Long
'' Opens a http session for a given site.
Public Declare Function InternetConnect lib "Wininet.dll" Alias "InternetConnecta" _
(Byval HinternetSession as Long, Byval sServername As String, Byval Nserverport AS INTEGER, _
Byval SUSERNAME AS STRING, BYVAL SPASSWORD AS STRING, BYVAL LSERVICE As Long, _
BYVAL LFLAGS As Long, Byval LCONText As Long AS Long
Public Declare Function InternetGetLastResponseInfo Lib "Wininet.dll" Alias "InternetGetlastResponseinfoa" (_ _
LPDWERROR As Long, _
Byval lpszbuffer as string, _
LPDWBUFFERLENGTH AS Long) as boolean
'' Type of Service to Access.
'' Opens an HTTP Request Handle.
Public Declare Function HttPopenRequest Lib "Wininet.dll" Alias "httpopenrequesta" _
(Byval Sverb as string, byval sobjectname as string, byval sversion as string, _
Byval Something as long, byval lflags as long, ByVal LCONTEXT AS long
'' Sends The Specified Request to The Http Server.
Public Declare Function httpsendrequest lib "Wininet.dll" alias "httpsendrequesta" (byval _
HHTTPREQUEST As Long, Byval Sheaders As String, Byval Lheaderslength As Long, ByVal SOPTIONAL AS _
String, Byval LOPTIONALLENGTH AS longue AS Integer '' Queries for Information About an HTTP REQUEST.
Public Declare Function httpqueryInfo lib "wininet.dll" alias "httpqueryinfoa" _
(Byval HHTTPREQUEST AS Long, Byval Linfolevel As Long, Byref Sbuffer As Any, _
BYREF LBUFFERLENGTH AS Long, Byref Lindex As Long AS Integer
'INTERNETERRORDLG
Public Declare Function InternetRrordlg LIB "Wininet.dll" _
(Byval HinterNet As Long, Byval Dwerror As Long, BYVAL DWFLAGS AS Long, Byval LPPVDATA AS long) As long
Public Declare Function GetDesktopWindow Lib "User32.dll" () AS Long
'' The Possible Values for the Linfolevel Parameter Include:
'' Reads Data from a Handle Opened by The HttpopenRequest function.
Public Declare Function InternetReadFile LIB "Wininet.dll" _
(Byval Hfile As Long, Byval Sbuffer AS String, Byval Lnumbytestoread As Long, _
LnumberofbytesRead as long) AS Integer
Public Declare Function httpsendrequestex lib "wininet.dll" alias "httpsendrequestexa" _
(Byval HHTTPREQUEST AS Long, lpbuffersin as internet_buffers, byval lpbuffersout as long, _
Byval dwflags as long, Byval DWCONText As long) AS Long
Public Declare Function HttpendRequest Lib "Wininet.dll" Alias "httpendrequesta" _
(Byval Hhttprequest As Long, Byval Lpbuffersout As Long, _
Byval dwflags as long, Byval DWCONText As long) AS Long
Public Declare Function InternetWriteFile Lib "Wininet.dll" _
(Byval Hfile As Long, Byval Sbuffer AS String, _
Byval lunumberofbyteoread as long, _
LnumberofbytesRead as long) AS Integer
Public Declare Function FtPopenfile Lib "Wininet.dll" Alias _
"Ftpopenfilea" (Byval HFTPSession as stay, _byval sfilename as string, byval laccess as long, _
BYVAL LFLAGS As Long, Byval LCONText As Long AS Long
Public Declare Function FTPDeletefile LIB "Wininet.dll" _
Alias "ftpdeletefilea" (Byval HFTPSession as Long, _
BYVAL LPSZFILENAME AS STRING) AS BOOLEAN
Public Declare Function InternetSetoption Lib "Wininet.dll" Alias "InternetSetoptiona" _
(Byval Hinternet As Long, ByVal LOPTION As Any, BYVAL LBUFFERLENGTH AS Long AS Integer
Public Declare Function InternetSetOptionstr Lib "Wininet.dll" Alias "InternetSetoptiona" _
(Byval Hinternet As Long, Byval SBuffer AS String, BYVAL LBUFFERLENGTH AS long) AS Integer
'' Closes A Single Internet Handle OR A Subtree of Internet Handles.
Public Declare Function InternetCloseHandle Lib "Wininet.dll" _
(Byval Hinet As Long) AS Integer
'' Queries an internet option on the specified handle
Public Declare Function InternetQueryOption Lib "Wininet.dll" Alias "InternetQueryOptiona" _
(Byval Hinternet As Long, ByVal LOPTION As Any, Byref LBufferLength As long) AS Integer
'' Returns the Version Number of Wininet.dll.
Public const interface_option_version = 40
'' Contains The Version Number of The Dll That Contains The Windows Internet
'' Functions (Wininet.dll). This Structure is buy for the
'' Internet_option_version flag to the internetQueryOption function.
'' Adds One or More Http Request Headers to the Http Request Handle.
Public Declare Function httpaddrequestheaders lib "wininet.dll" alias "httpaddrequestheadersa" _ (Byval HhttpRequest as long, byval sheaders as string, byval Lheaderslength As long, _
BYVAL LMODIFIERS As long) AS Integer
'' Flags to modify the semantics of this function. Can becombination of these values:
Public Declare Function InternetDial Lib "Wininet.dll" _
(Byval Hwnd As Long, Byval Sconnectoid As String, _
BYVAL DWFLAGS As Long, LPDWConnection As Long, BYVAL DWRESERVED AS Long AS Long
Public Declare Function InternetHangup LIB "Wininet.dll" _
(BYVAL DWCONNECTION As Long, Byval DwReserved As Long
Public Declare Function Internetopenurl Lib "Wininet.dll" Alias "Internetopenurla" _
(Byval HinternetSession as Long, Byval SURL AS String, _
Byval sheaders as string, byval Lheaderslength as long, _
BYVAL LFLAGS As Long, Byval LCONText As Long AS Long