如何获得当前程序的运环境是在调试状态下?
 我地程序中采用了钩子函数,运行后产生任一错误,都会导至程序的全面崩溃(每次都得重新进入VB)。
如果能得到此程序的运行环境是在调试状态或是在可执行状态下,那就不用哪么累了.(我目前的解方法是在调试时将hook函数注释掉)

解决方案 »

  1.   

    楼主将程序编译之后,使用那个EXE文件吧。
      

  2.   

    变通一下,在程序中调用下面的程序如果返回false则是调试状态下Private Function Compiled() As Boolean
       On Error GoTo NotCompiled
       Debug.Print 1 / 0
       Compiled = True
    NotCompiled:
    End Function
      

  3.   

    Private Sub Command1_Click()
        If App.LogMode = 0 Then
            MsgBox "运行在调试模式"
        Else
            MsgBox "运行在运行模式"
        End If
    End Sub
      

  4.   

    使用GetModuleFileName函数,看最右边的 7 个字符是否等于 "VB6.EXE",Option ExplicitPrivate Declare Function GetModuleFileName Lib "kernel32" Alias _
            "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As _
            String, ByVal nSize As Long) As LongFunction IsRunUnderVB6() As Boolean
     Dim S As String
     Dim Length As Long
     Length = 256
     S = String(Length, 0)
     Call GetModuleFileName(0, S, Length)
     S = Left(S, InStr(S, Chr(0)) - 1)
     IsRunUnderVB6 = UCase(Right(S, 7)) = "VB6.EXE"
    End FunctionPrivate Sub Command1_Click()
    If IsRunUnderVB6 Then
    MsgBox "调试"
    Else
    MsgBox "运行"
    End If
    End Sub