Trouble with 'GetExitCodeProcess'
Posted on 1998-11-05
When using the Shell function in conjuction with the OpenProcess API and the GetExitCodeProcess, the program errors out when the GetExitCodeProcess in encountered. It also closes out the VB IDE. This was tested in VB5 and VB6 under Windows NT 4.0 with the same results. I have declared the API's properly. The function I shelled to is notepad.exe.
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess as Long, ByVal bInheritHandle as Long, ByVal dwProcessId as Long) as Long
Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess as Long, ByVal lpExitCode as Long) as Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject as Long) as Long
Private Const PROCESS_QUERY_INFORMATION = &H400&
Private Const STILL_ACTIVE = &H310&
Public Function WaitOnProgram() as Boolean
Dim lExit as Long, lProg as Long, lReturnValue as Long
Dim sShellCommand as String
lProg = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(sShellCommand, vbNormalFocus))
lReturnValue = GetExitCodeProcess(lProg, lExit)
Loop While lExit = STILL_ACTIVE
WaitOnProgram = lExit
The error is a 'Start:VB5(6).exe - Application Error
The instruction at "0x77f199a9" referenced memory at "0x00000000". The memory could not be "written".