Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Replacement for GetModuleUsage

As we know GetModuleUsage is obsolete in the Windows 32-bit API. What is a good method of determining if another application (16 or 32 bit) that was shelled is still running and will work in an application written in VB5 when running on Windows95/98 and NT?
0
EEI
Asked:
EEI
  • 4
  • 4
1 Solution
 
nietodCommented:
You can use WaitForSingleObject() on the shelled process's process handle.  The wait procedure will return when the process has terminated (or the time limit has expired).  Your code can use a 0 wait time for a "quick check" or can use a longer wait time (evien infinite) if it needs to actually wait.

Let me know if you have questions.
0
 
EEIAuthor Commented:
This seems that it would be a great solution, simple and effective. Except that everything hangs until the time runs out. It is just as if WaitForSingleObject needed DoEvents.
0
 
EEIAuthor Commented:

What I said in the last comment got me to thinking that I could put WaitForSingleObject into a Do Loop  with the time set to zero and watch for a return value of other than 258. That seemed to do the trick!!! I also noticed that I could do the same with GetExitCodeProcess. I wonder if there would be advantages of using one over the other?

Thanks.
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
nietodCommented:
Use WaitForSingleObject() over GetExitCodeProcess().  It will be more efficient.  but you don't want to keep repeating with a short wait interval (0)--that can use too much processor time needlessly.  Can you post your code?
0
 
MadshiCommented:
How about creating a thread that does nothing but call WaitForSingleObject? When returning from that call the thread could post a message to your main thread with the ExitCode as parameter and then terminate itself (simply by running out of the function).

Regards, Madshi.
0
 
nietodCommented:
Madshi's suggestions is probably the most common way that this is used, but there are others depending on your needs.
0
 
EEIAuthor Commented:
Here is what I have. Launch is a good size proceedure that does a number of things (reads & writes ini files etc.) but it basically contains "Shdl=OpenProcess(&H400,0,Shell("File.exe",1)".

Dim Shdl as Long

Shdl = Launch((SetUp.GCodePath.Text))
Do
      RetVal = WaitForSingleObject(Shdl, 0)
      DoEvents: Sleep 100
Loop While RetVal = 258

If this looks ok then I think I have it.

Thank you very much for your help.
0
 
nietodCommented:
That is one way of using it.  I would make the following improvements.

Don't look for "258"  You are not guarantteed that it will be 258 on all platforms!  (but it probably will be)  Instead look for "WAIT_TIMEOUT".  i.e

while (RetVal == WAIT_TIMEOUT)

or better yet,  wait until successfull.

while (RetVal != WAIT_OBJECT_O)

either will be an improvement.  Next, if you keep this design, why not put the "sleep wait" into the WaitForSingleObject().  i.e. drop the sleep(100) and wait inside WaitForSingleObject() for 100?  The main advantage of this is that when the process ends, WaitForSingleObject will return without waiting the full 100.  If the process ends while you are in the sleep(), you will have to finish the full sleep before you can start the wait which will ends immediately.

One more thing, if "DoEvents" just involves handling messages.  Then there is a different wait() procedure you should use.  It allows you to wait and handle messages "at the same time" sorf of. If DoEvents involves lots of different things, then this is the way to go.  (Or you can go with madshi's suggestion if (a) you are writing a multithreaded application and (b) the waiting code (DoEvents)  handles mesages and could be notified by a message sent from the waiting thread.
0
 
EEIAuthor Commented:
I appreciate the timeliness and the dilligence on the part of both of you to provide a most helpful solution. Look foward to working with you.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now