Results 1 to 3 of 3

Thread: Can't get this code to work when combined

  1. #1
    Guest

    Angry

    FRUSTRATED!!!! My code is supposed to disconnect the DUN connection at a
    specified time (which it does without fail), next my code is supposed to
    close a program. Any program will do, we can use "Notepad" for this
    example. I've tried three different ways to close Notepad, they all work
    when tested, however when I place the code at the end or begining of my
    close DUN code it NEVER closes the program! I tried creating a Public
    Fnction and a Public Sub that closed the program and was called from the
    close DUN code but both produced the same results. Someone has to have
    seen this before, I've been chasing this bug for several day now and I'm
    burnt out on it!

    I've tried the TerminateProcess API function as seen here:
    http://www.freevbcode.com/ShowCode.Asp?ID=935

    Hopefully someone can help out here. I am lost, I'm not getting any erros,
    just not working.
    ********************************Declarations*******************************
    Option Explicit

    Private Declare Function WaitForSingleObject Lib "kernel32" _
    (ByVal hHandle As Long, _
    ByVal dwMilliseconds As Long) As Long

    Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" _
    (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long

    Private Declare Function PostMessage Lib "user32" _
    Alias "PostMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    Private Declare Function IsWindow Lib "user32" _
    (ByVal hwnd As Long) As Long

    'Constants used by the API functions
    Const WM_CLOSE = &H10
    Const WM_QUIT = &H12
    Const INFINITE = &HFFFFFFFF
    ********************************CODE*******************************
    Public Sub HangUp(HangUpTime As Date)

    Dim i As Long
    Dim lpRasConn(255) As RasConn
    Dim lpcb As Long
    Dim lpcConnections As Long
    Dim hRasConn As Long
    Dim hWindow As Long

    Do
    If Now() >= HangUpTime Then
    Call ActiveConnection
    If ActiveConnection = True Then
    lpRasConn(0).dwSize = RAS_RASCONNSIZE
    lpcb = RAS_MAXENTRYNAME * lpRasConn(0).dwSize
    lpcConnections = 0
    ReturnCode = RasEnumConnections(lpRasConn(0), lpcb, lpcConnections)
    If ReturnCode = ERROR_SUCCESS Then
    For i = 0 To lpcConnections - 1
    If Trim(ByteToString(lpRasConn(i).szEntryName))= Trim(gstrISPName) Then
    hRasConn = lpRasConn(i).hRasConn
    ReturnCode = RasHangUp(ByVal hRasConn)
    End If
    Next i
    End If
    hWindow = FindWindow(vbNullString, "Notepad")
    If hWindow <> 0& Then 'found it
    PostMessage hWindow, WM_CLOSE, 0&, ByVal 0&
    End If
    Unload Me
    Exit Sub
    Else
    hWindow = FindWindow(vbNullString, "Notepad")
    If hWindow <> 0& Then 'found it
    PostMessage hWindow, WM_Close, 0&, ByVal 0&
    End If
    Unload Me
    Exit Sub
    End If
    Else
    For i = 1 To 30
    Sleep (1000)
    DoEvents
    Next i
    End If
    Loop
    End Sub
    ************************************************************************

    Sorry for the long post

    TIA


  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Looks right, you could put your code inside code tags so anyone reading this could easier see your problem, the postmessage call seems to be correct, does this line get fired? put break on that line and check out if you get a handle. If not, put a break before the first if including that line and follow the procedure step by step(F8)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Guest

    Unhappy CODE FOR HELP

    Ok, rather than try & post everything, I created a small project with all the modules, & the form.
    It can be downloaded at:
    http://www.bigbadbowtie.coloradok5.com/TEMP_CODE.htm

    The actual program I am trying to close is AudioGalaxy Satellite Beta. It's available for download at http://www.audiogalaxy.com/betatest2, if anyones so inclined to test it. I'm starting to think it's a problem with their program not mine . Anyway I use WM_QUIT because of a programing glitch in theirs, WM_CLOSE just minimizes their program. IF someone could test it for I'd appreciate it. Like I said the Close Program part of mycode WORKS, but NOT when combbined with the close DUN portion. You could maybe also try another programin place of AudioGalaxy Satellite to prove it's theirs not mine!

    TIA




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