Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trouble with 'GetExitCodeProcess'

Posted on 1998-11-05
2
Medium Priority
?
783 Views
Last Modified: 2008-02-01
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 statements:
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

Constants:
Private Const PROCESS_QUERY_INFORMATION = &H400&
Private Const STILL_ACTIVE = &H310&

Function:
Public Function WaitOnProgram() as Boolean
  Dim lExit as Long, lProg as Long, lReturnValue as Long
  Dim sShellCommand as String

  sShellCommand="c:\winnt\notepad.exe"
  lProg = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(sShellCommand, vbNormalFocus))
  Do
    lReturnValue = GetExitCodeProcess(lProg, lExit)
    DoEvents
    Sleep 1000
  Loop While lExit = STILL_ACTIVE
  CloseHandle lProg
  WaitOnProgram = lExit
End Function

The error is a 'Start:VB5(6).exe - Application Error
The instruction at "0x77f199a9" referenced memory at "0x00000000". The memory could not be "written".
0
Comment
Question by:RhinoDude
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
Mirkwood earned 400 total points
ID: 1443358
I would blame the doevents. You are making a recursive call.
try replacing doevents with a timer.
To after OpenProcess, activate a timer
on the timer tick, test the exitcode
when the exitcode is still_activate deactive the timer and close the application.

Much more safe.
0
 

Author Comment

by:RhinoDude
ID: 1443359
After the OpenProcess I enabled the timer.

I changed the do loop to:
Do
  doevents
Loop While ProgramRunning

This enables repaint if necessary.

The timer routine is:
Dim lReturnValue As Long
Dim lExit As Long
     
'get status
lReturnValue = GetExitCodeProcess(lProg, lExit)
Sleep 100

lProg and STILL_ACTIVE were made public.
The Declare for the GetExitCodeProcess was made public.

thanks for the quick response!

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question