[AccessD] FTP to a web site

Jim Dettman jimdettman at verizon.net
Sat Apr 1 12:53:19 CDT 2023


Stuart,

 Yes, I didn't show the declares, but they are simple enough.

 I generally don't like any situation where I hand off control to something
and say, "I'll wait to hear from you" and possibly never do.

 So I use a loop like this, which allows me to code in an abort if I choose,
show an animation, or whatever.  

Jim.



-----Original Message-----
From: AccessD On Behalf Of Stuart McLachlan
Sent: Friday, March 31, 2023 9:09 PM
To: Access Developers discussion and problem solving
<accessd at databaseadvisors.com>
Subject: Re: [AccessD] FTP to a web site

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

-- 
AccessD mailing list
AccessD at databaseadvisors.com
https://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list