Solved

Replacement for GetModuleUsage

Posted on 1998-10-26
9
234 Views
Last Modified: 2013-12-03
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
Comment
Question by:EEI
[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
  • 4
  • 4
9 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1415631
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
 

Author Comment

by:EEI
ID: 1415632
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
 

Author Comment

by:EEI
ID: 1415633

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 22

Expert Comment

by:nietod
ID: 1415634
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1415635
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
 
LVL 22

Expert Comment

by:nietod
ID: 1415636
Madshi's suggestions is probably the most common way that this is used, but there are others depending on your needs.
0
 

Author Comment

by:EEI
ID: 1415637
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
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1415638
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
 

Author Comment

by:EEI
ID: 1415639
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 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