Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    115

    [VB6] Problema coi link

    Ciao a tutti, un po' di tempo fa MItaly mi aveva dato questo codice per fare aprire links direttamente col browser predefinito, solo che ultimamente ho qualche problema a farlo funzionare:

    Modulo
    codice:
    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Public Const SW_NORMAL = 1
    Codice Evento
    codice:
    Public Sub Command1_Click()
        Dim ret As Long
        ret = ShellExecute(Me.hWnd, "open", "http://www.tuosito.com", vbNullString, vbNullString, SW_NORMAL)
        If ret<=32 Then MsgBox "Impossibile aprire la pagina web." & vbCrLf & "Codice di errore di ShellExecute: " & LTrim(CStr(ret))+".",vbCritical,"Errore"
    End Sub
    In pratica quando eseguo da Visual basic, facendo scattare l'evento mi da l'errore del ret minore/uguale a 32 ma apre lo stesso il browser con la pagina, mentre invece se compilo l'eseguibile non da nessun errore ed apre normalmente la pagina. E' giusto che dia l'errore in VB6? Se no, come risolvo? Grazie

  2. #2
    Teoricamente non è corretto: di seguito un estratto dalla documentazione di ShellExecute:
    Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise. The following table lists the error values. [...]
    0 The operating system is out of memory or resources.
    ERROR_FILE_NOT_FOUND The specified file was not found.
    ERROR_PATH_NOT_FOUND The specified path was not found.
    ERROR_BAD_FORMAT The .exe file is invalid (non-Microsoft Win32® .exe or error in .exe image).
    SE_ERR_ACCESSDENIED The operating system denied access to the specified file.
    SE_ERR_ASSOCINCOMPLETE The file name association is incomplete or invalid.
    SE_ERR_DDEBUSY The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed.
    SE_ERR_DDEFAIL The DDE transaction failed.
    SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
    SE_ERR_DLLNOTFOUND The specified dynamic-link library (DLL) was not found.
    SE_ERR_FNF The specified file was not found.
    SE_ERR_NOASSOC There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
    SE_ERR_OOM There was not enough memory to complete the operation.
    SE_ERR_PNF The specified path was not found.
    SE_ERR_SHARE A sharing violation occurred.
    .
    Che codice di errore ti restituisce esattamente?
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    115
    Modifico:
    l'errore me lo da ancora: lo da solo quando firefox non è aperto, mentre quando lo è già apre una scheda con la pagina e non dà errori.
    L'errore che dà quando deve aprire firefox è:

    Impossibile aprire la pagina web.
    Codice errore di ShellExecute: 2.

    PS: premetto che la pagina linkata è esistente... tanto è vero che anche se dà l'errore poi firefox viene aperto correttamente proprio su quella pagina!

  4. #4
    Boh... sarebbe ERROR_FILE_NOT_FOUND...
    Amaro C++, il gusto pieno dell'undefined behavior.

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    115
    Eh, appunto per quello ho specificato che la pagina esiste... non esistesse capirei l'errore! Secondo te risolvere semplicemente levando il controllo dell'errore nel caso che non si capisce perchè lo faccia è un'idea troppo squinternata? :S
    Perchè ora che ho visto che l'errore lo da solo a firefox chiuso, ho provato ed anche con l'eseguibile compilato dà l'errore! Boh... non so dove sbattere la capoccia

  6. #6
    Sì, puoi levare il controllo dell'errore... anche perché è un controllo che non ha senso per i siti internet, visto che la ShellExecute non sa nulla dell'indirizzo che gli hai specificato, è il browser che di fatto vede se esiste.
    Amaro C++, il gusto pieno dell'undefined behavior.

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    115
    Togliendo il controllo posso anche togliere il modulo e ret=...?

  8. #8
    No, il modulo va lasciato, mentre devi cambiare l'altro pezzo di codice in questo modo:
    codice:
    Public Sub Command1_Click()
        ShellExecute(Me.hWnd, "open", "http://www.tuosito.com", vbNullString, vbNullString, SW_NORMAL)
    End Sub
    .
    Amaro C++, il gusto pieno dell'undefined behavior.

  9. #9
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    115
    Ok, rivedendolo sì, ho fatto così... grazie comunque! Sempre molto disponibile

  10. #10
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    115
    C'è un problema però... lui si aspetta un "=".... infatti mi dice:

    Compile Error:
    Expected: =

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.