I was wondering about how to run external applications using Visual Basic 6.0. Running the application is not the problem, my problem is that I want to run the external application in a Modal way, that is, my application is inactive while the external application is running.
Option Explicit
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFF
Private Const WAIT_OBJECT_0 = 0
Private Const WAIT_TIMEOUT = &H102
Private Sub Form_click()
Dim llngProcID As Long
Dim llngWinHwnd As Long
Dim llngRetVal As Long
llngProcID = Shell("c:\windows\system32\notepad.exe", vbNormalFocus)
If llngProcID <> 0 Then
llngWinHwnd = OpenProcess(SYNCHRONIZE, 0, llngProcID)
DoEvents
If llngWinHwnd <> 0 Then
llngRetVal = WaitForSingleObject(llngWinHwnd, INFINITE)
CloseHandle (llngWinHwnd)
End If
End If
MsgBox "Finished"
End Sub
This code solves me, but the way in which it blocks the vb6 application leaving it in "Not Responding" is not very pleasant, if anyone had any other way to do this, I would appreciate it.