CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    kernel32 lib problems

    Hi,

    In a program I wrote, I used following function that calls the kernel32 lib
    to check if a proces (a Dos program that writes a ascci-file) has terminated
    (see below).

    It works fine under Windows 95 but with NT4.0 id doesn't work.

    What could be the problem.

    Please help me,

    Rik


    Declare Function CloseHandle Lib "kernel32" (byval hObject as Long) as Long
    Declare Function OpenProcess Lib "kernel32" (byval dwDesiredAccess as Long,
    byval bInheritHandle as Long, byval dwProcessID as Long) as Long
    Declare Function GetExitCodeProcess Lib "kernel32" (byval hProcess as Long,
    lpExitCode as Long) as Long


    public Function TestIfProcessStillAlive(ProcessID as Long) as Boolean
    Dim Alive_ones as Long
    Dim LoopTroughProcess as Long
    Dim AlivePulse as Long
    Dim hProcess as Long
    Dim lngExitCode as Long

    AlivePulse = 0
    If ProcessID <> 0 then
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, false, ProcessID)
    If hProcess <> 0 then
    GetExitCodeProcess hProcess, lngExitCode
    else 'process not found
    TestIfProcessStillAlive = false
    Exit Function
    End If

    'if you open a handle then you have to close it too
    CloseHandle (hProcess)
    else
    TestIfProcessStillAlive = false
    Exit Function
    End If

    If lngExitCode = 259 then
    TestIfProcessStillAlive = true
    else
    If lngExitCode = 0 then TestIfProcessStillAlive = false
    End If

    End Function






  2. #2
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: kernel32 lib problems

    Hi,
    I would guess 'Secuirity' problems!. NT is more stringent than '95.
    You have not mentioned as to how your are starting the other process (DOS program). Check out ShellExecute (API)instead of just Shell (VB).
    Also what you are trying to do can be accomplished by WaitforSingleObject API. and the process goes into a 'signaled' state when it terminates. This call is performance-tuned too.

    Ravi


  3. #3
    Guest

    Re: kernel32 lib problems

    I was using shell. I'll try shellexecute.
    By the way, where can I find some information about the API declarations?

    Thanks,
    Rik



  4. #4
    Guest

    Re: kernel32 lib problems

    Searching for the waitforsingleobject function,is the msdn library I found a solution. (Tip 173: http://msdn.microsoft.com/library/te...dn_msdn173.htm).

    Thanks for the tip on the waitforsingleobject function.



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

Featured