From: Sarah M. Weinberger on

I have a code fragment that worked great under VB6 in a Microsoft Windows XP
environment, but I finally upgraded to Windows Vista and am having trouble.
I did a Google search, but that was no help.

The following code run from within the IDE produces an Overflow #6 error. I
am using VB6 with SP6 installed.

To replicate create a new project and add a button. Here is the entire code
for the inside. I added extra code to help isolate the problem.

Option Explicit

Private Declare Function GetModuleFileName Lib "kernel32" Alias
"GetModuleFileNameA" (ByVal hModule As Integer, ByVal lpFileName As String,
ByVal nSize As Integer) As Integer
Private Declare Function GetModuleHandle Lib "kernel32" Alias
"GetModuleHandleA" (ByVal lpModuleName As String) As Long

Private Sub Command1_Click()
Dim bIsIDE As Boolean

bIsIDE = IsInIDE()
End Sub

Private Function IsInIDE() As Boolean
Dim hModule As Long, lLen As Long
Dim strModule As String * 256

'Initialize the string.
strModule = Space$(255)

hModule = GetModuleHandle(vbNullString)
lLen = Len(strModule)
iLen = lLen

'Get the module name.
GetModuleFileName hModule, strModule, iLen

'Return the result.
IsInIDE = (UCase$(Trim$(strModule)) Like "*VB6.EXE*")
End Function