C
Chas2002
Guest
Hi all,
(This has been driving me nuts and I hope someone can point me in the right direction)...
I have a module that shells another program..I need to have MS Access wait until that process (the shell) is finished.
The shell is TeraTerm and it opens a com port and communicates with a switch. Along with teraterm opens a Log File and a macro. I would like for MS Access to check to see if TeraTerm or the Log File or the Macro is still open - If so, then have MS Access pause until TeraTerm is done.
This is what I have and it works sometimes, but looking for a better way:
' ************CODE START ************
Option Compare Database
Private Const WM_CLOSE = &H10
Private Const INFINITE = &HFFFFFFFF
Private Declare Function apiPostMessage _
Lib "user32" Alias "PostMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) _
As Long
Private Declare Function apiFindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
Private Declare Function apiWaitForSingleObject _
Lib "kernel32" Alias "WaitForSingleObject" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) _
As Long
Private Declare Function apiIsWindow _
Lib "user32" Alias "IsWindow" _
(ByVal hWnd As Long) _
As Long
Private Declare Function apiGetWindowThreadProcessId _
Lib "user32" Alias "GetWindowThreadProcessId" _
(ByVal hWnd As Long, _
lpdwProcessID As Long) _
As Long
-----------------------------------------------
Function fCloseApp()
Dim sngTime As Single
sngTime = Timer
lpClassName = "FTDlg32"
Dim lngRet As Long, hWnd As Long, pID As Long
hWnd = apiFindWindow(lpClassName, vbNullString)
If (hWnd) Then
Do While Timer - sngTime < 4
Loop
Call fCloseApp
Else
lngRet = apiPostMessage(hWnd, WM_CLOSE, 0, ByVal 0&)
Call apiGetWindowThreadProcessId(hWnd, pID)
Call apiWaitForSingleObject(pID, INFINITE)
fCloseApp = Not (apiIsWindow(hWnd) = 0)
End If
Reset
Call fCloseApp1
End Function
'************* Code End ***************
I got this as an example code, the window name is : FTDlg32, so if that window is still open, wait..
Thanks,
Chas2002
(This has been driving me nuts and I hope someone can point me in the right direction)...
I have a module that shells another program..I need to have MS Access wait until that process (the shell) is finished.
The shell is TeraTerm and it opens a com port and communicates with a switch. Along with teraterm opens a Log File and a macro. I would like for MS Access to check to see if TeraTerm or the Log File or the Macro is still open - If so, then have MS Access pause until TeraTerm is done.
This is what I have and it works sometimes, but looking for a better way:
' ************CODE START ************
Option Compare Database
Private Const WM_CLOSE = &H10
Private Const INFINITE = &HFFFFFFFF
Private Declare Function apiPostMessage _
Lib "user32" Alias "PostMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) _
As Long
Private Declare Function apiFindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
Private Declare Function apiWaitForSingleObject _
Lib "kernel32" Alias "WaitForSingleObject" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) _
As Long
Private Declare Function apiIsWindow _
Lib "user32" Alias "IsWindow" _
(ByVal hWnd As Long) _
As Long
Private Declare Function apiGetWindowThreadProcessId _
Lib "user32" Alias "GetWindowThreadProcessId" _
(ByVal hWnd As Long, _
lpdwProcessID As Long) _
As Long
-----------------------------------------------
Function fCloseApp()
Dim sngTime As Single
sngTime = Timer
lpClassName = "FTDlg32"
Dim lngRet As Long, hWnd As Long, pID As Long
hWnd = apiFindWindow(lpClassName, vbNullString)
If (hWnd) Then
Do While Timer - sngTime < 4
Loop
Call fCloseApp
Else
lngRet = apiPostMessage(hWnd, WM_CLOSE, 0, ByVal 0&)
Call apiGetWindowThreadProcessId(hWnd, pID)
Call apiWaitForSingleObject(pID, INFINITE)
fCloseApp = Not (apiIsWindow(hWnd) = 0)
End If
Reset
Call fCloseApp1
End Function
'************* Code End ***************
I got this as an example code, the window name is : FTDlg32, so if that window is still open, wait..
Thanks,
Chas2002