2012-08-14 60 views

回答

1

我在網上找到了你的問題在C#中的解決方案,所以這是我可以建議的VB版本。只要確保您導入System.Runtime.InteropServices。

<Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _ 
     Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean 
       End Function 

       Public Structure Struct_INTERNET_PROXY_INFO 
         Public dwAccessType As Integer 
         Public proxy As IntPtr 
         Public proxyBypass As IntPtr 
       End Structure 

       Private Sub RefreshIESettings(ByVal strProxy As String) 
         Const INTERNET_OPTION_PROXY As Integer = 38 
         Const INTERNET_OPEN_TYPE_PROXY As Integer = 3 

         Dim struct_IPI As Struct_INTERNET_PROXY_INFO 

         ' Filling in structure 
         struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY 
         struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy) 
         struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local") 

         ' Allocating memory 
         Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI)) 

         ' Converting structure to IntPtr 
         Marshal.StructureToPtr(struct_IPI, intptrStruct, True) 

         Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI)) 
    End Sub 
+0

好吧,這個作品!非常感謝。 – Ewen 2012-08-29 19:01:42