VB(A) and the 32-Bit API

A similar principle to GetModuleUsage

It may not look neat, but it's a lot tighter than window handles. This approach should work in 32-bit VB4 as well. Remember that if you support Excel 5 you need to keep GetModuleUsage, and test which approach to use as shown earlier.


  ' Each on a single line, of course!
  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, lpExitCode As Long) As Long 
  Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 
  Public Const STILL_ACTIVE = &h103 
  Public Const PROCESS_QUERY_INFORMATION = &h400
  Sub Shell32Bit(ByVal JobToDo As String)         ' JobToDo is name of program to run
  Dim hProcess As Long, RetVal As Long            ' Next line launches job as icon, captures process id
  hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, 6))
  Do
    GetExitCodeProcess hProcess, RetVal           ' Get status of process
    DoEvents: Sleep 100                           ' Sleep command recommended in addition to DoEvents
  Loop While RetVal = STILL_ACTIVE                ' Look while process is active
  End Sub


There are certainly other differences between Win 3.X and Win95 API calls which may cause unexpected problems. However, until Appleman updates his API bible, we'll have to struggle on as best we can! If you have Compuserve access, try the EXCEL, PROGMSA or VBPJFO forums for assistance.


[HOME] [TABLE OF CONTENTS] [SEARCH]