by Serge Lachapelle (10 Submissions)
Category: Debugging and Error Handling
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)
return TRUE if inside IDE, return FALSE if in compiled EXE, work in standard EXE and in DLL
Private Type MODULEENTRY32
dwSize As Long
th32ModuleID As Long
th32ProcessID As Long
GlblcntUsage As Long
ProccntUsage As Long
modBaseAddr As Long
modBaseSize As Long
hModule As Long
szModule As String * 256
szExePath As String * 260
End Type
Private Const TH32CS_SNAPMODULE = &H8
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Module32First Lib "kernel32" (ByVal hSnapshot As Long, uProcess As MODULEENTRY32) As Long
Private Declare Function Module32Next Lib "kernel32" (ByVal hSnapshot As Long, uProcess As MODULEENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Public Function IsDebug() As Boolean
Dim qwe As String
Dim hProcess As MODULEENTRY32, hMod&, hSnapshot&
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId)
hProcess.dwSize = Len(hProcess)
hMod = Module32First(hSnapshot, hProcess)
qwe = Left$(hProcess.szExePath, InStr(hProcess.szExePath, vbNullChar) - 1)
If LCase$(Right$(qwe, 4)) <> ".exe" Then
Do
hMod = Module32Next(hSnapshot, hProcess)
qwe = Left$(hProcess.szExePath, InStr(hProcess.szExePath, vbNullChar) - 1)
Loop Until (LCase$(Right$(qwe, 4)) = ".exe") Or (hMod = 0)
End If
IsDebug = LCase(hProcess.szExePath) Like "*vb#.exe*"
CloseHandle hSnapshot
End Function