Soyez le premier à donner votre avis sur cette source.
Snippet vu 5 142 fois - Téléchargée 31 fois
Private Const S_FALSE = &H1 Private Const S_OK = &H0 'Only implemented as unicode... Private Declare Function IsValidURL Lib "URLMON.DLL" (ByVal pbc As Long, ByVal szURL As String, ByVal dwReserved As Long) As Long Private Sub Form_Load() 'KPD-Team 2001 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net MsgBox "Is valid URL: " + CStr(IsGoodURL("http://www.allapi.net")) MsgBox "Is valid URL: " + CStr(IsGoodURL("hxxp:/www.allapi.uhoh")) End Sub Public Function IsGoodURL(ByVal sURL As String) As Boolean 'The IsValidURL always expects a UNICODE string, but whenever 'VB calls an API function, it converts the strings to ANSI strings. 'That's why we're going to use a trick here. Before calling the function, 'We're going to convert the unicode string to unicode so we get a double 'unicode string. 'Before VB calls the API function, it converts our double unicode string 'to a normal unicode string; exactely what IsValidURL is expecting. sURL = StrConv(sURL, vbUnicode) 'Now call the function IsGoodURL = (IsValidURL(ByVal 0&, sURL, 0) = S_OK) End Function Private Const S_FALSE = &H1 Private Const S_OK = &H0 'Only implemented as unicode... Private Declare Function IsValidURL Lib "URLMON.DLL" (ByVal pbc As Long, ByVal szURL As String, ByVal dwReserved As Long) As Long Private Sub Form_Load() 'KPD-Team 2001 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net MsgBox "Is valid URL: " + CStr(IsGoodURL("http://www.allapi.net")) MsgBox "Is valid URL: " + CStr(IsGoodURL("hxxp:/www.allapi.uhoh")) End Sub Public Function IsGoodURL(ByVal sURL As String) As Boolean 'The IsValidURL always expects a UNICODE string, but whenever 'VB calls an API function, it converts the strings to ANSI strings. 'That's why we're going to use a trick here. Before calling the function, 'We're going to convert the unicode string to unicode so we get a double 'unicode string. 'Before VB calls the API function, it converts our double unicode string 'to a normal unicode string; exactely what IsValidURL is expecting. sURL = StrConv(sURL, vbUnicode) 'Now call the function IsGoodURL = (IsValidURL(ByVal 0&, sURL, 0) = S_OK) End Function
8 déc. 2003 à 21:55
@+
9 déc. 2003 à 04:29
9 déc. 2003 à 10:39
9 déc. 2003 à 13:54
surtout si on colle ca deux fois de suite, n'est-ce pas....
Non, vraiment, je trouve pas ça très bien.....
9 déc. 2003 à 19:01
'<
Private Const S_OK = &H0 'Retroune ça si l'URL est OK
Private Declare Function IsValidURL Lib "URLMON.DLL" (ByVal pbc As Long, ByVal szURL As String, ByVal dwReserved As Long) As Long 'API utilisée
Public Function URLOk(URL As String) As Boolean 'Retourne TRUE si l'URL est OK
Dim str As String
str = StrConv(URL, vbUnicode) 'L'API prend juste le Unicode
If IsValidURL(0, str, 0) = S_OK Then
URLOk = True 'URL OK
Else
URLOk = False 'URL Invalide
End If
End Function
'>
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.