Call the API to set proxy (VB) for the program instance)

Source: Internet
Author: User

In the document "setting the COOKIE and Temporary Folder paths of WebBrowser in VB", we introduced how to set the cookie Path for Webbrowser. Likewise, we can set a proxy for Webbrowser. However, if the program does not have the Webbrowser control and other network functions are used, how can I set a proxy? We can call the InternetSetOption function in wininet. dll. Okay. The core code is provided directly.

 

'================================================ =
'Declaring function: Set a proxy for this instance
'================================================ =
Private Const INTERNET_OPTION_PROXY = 38
Private Const URLMON_OPTION_USERAGENT = & hsf-001
Private Const INTERNET_OPEN_TYPE_PROXY = 3
Private Const INTERNET_OPTION_SETTINGS_CHANGED = 39
Private Declare Sub UrlMkSetSessionOption Lib "urlmon. dll" (ByVal dwOption As Long, pbuffer As Any, ByVal dwBufferLength As Long, ByVal dwreserved As Long)
Private Type INTERNET_PROXY_INFO
DwAccessType As Long
LpszProxy As String
LpszProxyBypass As String
End Type
Private Declare Function InternetSetOption Lib "wininet. dll "_
Alias "InternetSetOptionA "_
(ByVal hInternet As Long ,_
ByVal dwOption As Long ,_
ByRef lpBuffer As Any ,_
ByVal dwBufferLength As Long) As Long

'================================================ =
'Function name: SetProxy
'Function: sets a proxy for this instance.
'Function parameters: for example, SOCKS = 127.0.0.1: 1987
'================================================ =
Public Function SetProxy (ByVal Proxy As String)
Dim options As INTERNET_PROXY_INFO
Options. dwAccessType = INTERNET_OPEN_TYPE_PROXY
Options. lpszProxy = Proxy
Options. lpszproxybypass = ""
Internetsetoption 0, internet_option_proxy, options, lenb (options)
Internetsetoption internet_option_settings_changed, 0, 0, 0
End Function

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.