我正在测试一个应用程序,它检查网络中是否存在文件.在我的测试中,我故意拉网络插件,因此找不到文件.问题是这导致我的应用程序无响应至少15秒.我在VB6中使用了FileExists()和GetAttr()函
谢谢,
查理
对于LAN / WAN,您可以结合使用以下Win32 API调用来告诉您远程连接是否存在而无需处理网络超时:
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias _ "WNetGetConnectionA" (ByVal lpszLocalName As String, _ ByVal lpszRemoteName As String, ByRef cbRemoteName As Long) As Long Private Declare Function PathIsNetworkPath Lib "shlwapi.dll" Alias _ "PathIsNetworkPathA" (ByVal pszPath As String) As Long Private Declare Function PathIsUNC Lib "shlwapi.dll" Alias "PathIsUNCA" _ (ByVal pszPath As String) As Long
对于Internet,您可以使用Win32 API调用:
Private Declare Function InternetGetConnectedState Lib "wininet.dll" _ (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long Const INTERNET_CONNECTION_MODEM = 1 Const INTERNET_CONNECTION_LAN = 2 Const INTERNET_CONNECTION_PROXY = 4 Const INTERNET_CONNECTION_MODEM_BUSY = 8
这个VB站点有更多关于path oriented functions you can call in the Win32 API through VB.的讨论