Solved

Replacement for GetModuleUsage

Posted on 1998-10-26
9
232 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
SAPE.heur.AE935 Visual Studio 3 53
Example of WebAPI 7 33
Slow process to read Excel 15 137
SSRS troubles 4 68
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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