[AccessD] FTP to a web site

Stuart McLachlan stuart at lexacorp.com.pg
Fri Mar 31 20:08:31 CDT 2023


On 31 Mar 2023 at 10:03, Jim Dettman via AccessD wrote:

> 
> I use this with Shell():
> 
> Public Sub WaitWhileRunning(lngHWnd As Long)
> 
>         Dim lngExitCode As Long
>         Dim lnghProcess As Long
> 
> 10      lngExitCode = STILL_ACTIVE
> 20      lnghProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False,
> lngHWnd)
> 
> 30      If lnghProcess > 0 Then
> 40        Do While lngExitCode = STILL_ACTIVE
> 50          Call GetExitCodeProcess(lnghProcess, lngExitCode)
> 60          DoEvents
> 70        Loop
> 80      End If
> 
> 90      CloseHandle lnghProcess
> 
> End Sub
> 
>  And anything else that runs asynchronously.
> 
> Jim.
> 

You haven't posted the necessary Declares and Types that are needed with that Sub.  :)

Rather than a CPU consuming Do...Loop, it's much more effficient to use the OS's 
WaitForSingleObject.

Here's everything needed, including the Declares and Types:

Private Const STARTF_USESHOWWINDOW& = &H1
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

Private Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As LongPtr
    hStdOutput As LongPtr
    hStdError As LongPtr
End Type

Private Type PROCESS_INFORMATION
    hProcess As LongPtr
    hThread As LongPtr
    dwProcessID As Long
    dwThreadID As Long
End Type

Declare PtrSafe Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As LongPtr, ByVal dwMilliseconds As Long) As Long
Declare PtrSafe Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, _
          ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
          ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
          ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal hObject As LongPtr) As Long

Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
On Error GoTo Err_Handler

   Dim proc As PROCESS_INFORMATION
   Dim start As STARTUPINFO
   Dim ret As Long
   
   ' Initialize the STARTUPINFO structure:
   With start
      .cb = Len(start)
      If Not IsMissing(WindowStyle) Then
         .dwFlags = STARTF_USESHOWWINDOW
         .wShowWindow = WindowStyle
      End If
   End With
   ' Start the shelled application:

   ret = CreateProcessA(0, Pathname, 0, 0, 1, NORMAL_PRIORITY_CLASS, 0, 0, start, proc)
   ' Wait for the shelled application to finish:
   ret = WaitForSingleObject(proc.hProcess, INFINITE)
   ret = CloseHandle(proc.hProcess)

Exit_Here:
   Exit Sub
Err_Handler:
   MsgBox Err.Description, vbExclamation, "E R R O R"
   Resume Exit_Here
    
End Sub



More information about the AccessD mailing list