Solved

Replacement for GetModuleUsage

Posted on 1998-10-26
9
226 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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 the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

864 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now