Results 1 to 2 of 2

Thread: Trap error from spawned process

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    5

    Trap error from spawned process

    My VB program spawns the Kofax Ascent Capture scan process. How do I capture the errors that the scan process returns? If I run Ascent Capture by itself, it would normally display a msgbox with the error. When calling the auto-import feature from VB, it does not display anything.

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Call creatprocess then waitforsingleobject. GetExitCodeProcess will return an error condition IF THE CALLED PROGRAM SET ONE

    Code:
    'This program needs a common dialog box, named CDBox
    '  (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
    '   and select Microsoft Common Dialog control)
    Const INFINITE = &HFFFF
    Const STARTF_USESHOWWINDOW = &H1
    Private Enum enSW
        SW_HIDE = 0
        SW_NORMAL = 1
        SW_MAXIMIZE = 3
        SW_MINIMIZE = 6
    End Enum
    Private Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessId As Long
        dwThreadId As Long
    End Type
    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 Byte
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
    End Type
    Private Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
    End Type
    Private Enum enPriority_Class
        NORMAL_PRIORITY_CLASS = &H20
        IDLE_PRIORITY_CLASS = &H40
        HIGH_PRIORITY_CLASS = &H80
    End Enum
    Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    
    Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Function SuperShell(ByVal App As String, ByVal WorkDir As String, dwMilliseconds As Long, ByVal start_size As enSW, ByVal Priority_Class As enPriority_Class) As Long
        Dim pclass As Long
        Dim retval as Long
        Dim sinfo As STARTUPINFO
        Dim pinfo As PROCESS_INFORMATION
        'Not used, but needed
        Dim sec1 As SECURITY_ATTRIBUTES
        Dim sec2 As SECURITY_ATTRIBUTES
        'Set the structure size
        sec1.nLength = Len(sec1)
        sec2.nLength = Len(sec2)
        sinfo.cb = Len(sinfo)
        'Set the flags
        sinfo.dwFlags = STARTF_USESHOWWINDOW
        'Set the window's startup position
        sinfo.wShowWindow = start_size
        'Set the priority class
        pclass = Priority_Class
        'Start the program
        If CreateProcess(vbNullString, App, sec1, sec2, False, pclass, _
        0&, WorkDir, sinfo, pinfo) Then
            'Wait
            dwMilliseconds=10000  ' ten seconds
            WaitForSingleObject pinfo.hProcess, dwMilliseconds
            GetExitCodeProcess pinfo.hProcess,retval
            SuperShell = retval
        Else
            SuperShell = 0
        End If
    End Function
    
    
    MYreturncode = SuperShell( "somefile.EXE","c:\somewhere" , 0, SW_NORMAL, HIGH_PRIORITY_CLASS)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width