Page 3 of 3 FirstFirst 123
Results 81 to 98 of 98

Thread: Check if Application is Running Without Timer

  1. #81
    Lively Member CodeBlock's Avatar
    Join Date
    May 2005
    Location
    The_Universe.Milky_Way. Solar_System.Inner_Ring. The_Earth.Asia. India.TN. Chennai. Home_Sweet_Home
    Posts
    85

    Re: Check if Application is Running Without Timer

    Ahh, Your EXE doesnot even compile..

    Says, Cannot find project or library at that line of code.. and opens up the Reference dialog pointing to a MISSING reference: 'MISSING: Debug Object for AddressOf Subclassing'

    One of the latest errors i have ever seen.. lol

    HTH

  2. #82
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Check if Application is Running Without Timer

    The hInst value is a handle passed by value, there is no question about this.
    In fact, if you change it to byref then the hook procedure returns an error because you have an invalid handle

  3. #83
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Check if Application is Running Without Timer

    'MISSING: Debug Object for AddressOf Subclassing'
    Just remove that from the reference, it isn't needed.

  4. #84
    Lively Member CodeBlock's Avatar
    Join Date
    May 2005
    Location
    The_Universe.Milky_Way. Solar_System.Inner_Ring. The_Earth.Asia. India.TN. Chennai. Home_Sweet_Home
    Posts
    85

    Re: Check if Application is Running Without Timer

    Quote Originally Posted by moeur
    Just remove that from the reference, it isn't needed.
    Hey, moeur!! I am not a n00b.. lol.. have n't u still understood? I was just pointing out how Visual Basic is reacting differently... When u have a missing reference ( i know that u forgot to remove it while attaching your project ), why should VB complain on the line: strData = Space(dataStruct.cbData, 0)

    Oops, i dint put the above line in my previous post.. i was incomplete.. sorry!

    Space function accepts only one parameter which is the length of spaces you need. And so VB is supposed to error: Wrong number of arguments. But i was just playing around how VB reacts when u have a missing reference.. hmm, think i should not play around, just misleads to many stuff..

    Also, moeur, when u run your EXE press Ctrl+F5 with codes implementing Subclassing.. which makes sure u dont have any compiler error!

    And i dont understand your old quote:
    Quote Originally Posted by moeur
    The hInst value is a handle passed by value, there is no question about this.
    In fact, if you change it to byref then the hook procedure returns an error because you have an invalid handle
    Nopez, cant you see that any LPVOID is nothing but a pointer which is obviously pointer... You have just given your DLL code having the DllMain as:
    VB Code:
    1. Public Function DLLMain([hl]hInst As Long[/hl], ByVal fdwReason As Long, _
    2.   lpvReserved As Long) As Long
    which is ByRef.. What are you trying to tell?? You seem to contradict your own code

    Anyway, i will be back with the working code of your Notepad Hook.

  5. #85
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Check if Application is Running Without Timer

    Here is the component.

    This DLL was first featured in a VBPJ article by Matt Curland about subclassing with VB5. Its main purpose is to allow breaking into and stepping through code that subclasses windows, something not directly supported by VB.

    To enable it you would change the compiler directive int cSubClass module to
    VB Code:
    1. #Const DEBUGWINDOWPROC = -1
    However, set it back to zero before compiling.

    For now though, you can even disable the subclassing until we fix the dll problem. Just comment out this code in the form module cmdHook_Click event
    VB Code:
    1. 'subclass this form to receive callback messages
    2.     If Not SubClass.Enable(Me.hwnd) Then
    3.         MsgBox "Subclassing Failed"
    4.         Exit Sub
    5.     End If
    Attached Files Attached Files

  6. #86
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Check if Application is Running Without Timer

    VB Code:
    1. Public Function DLLMain(hInst As Long, ByVal fdwReason As Long, _
    2.   lpvReserved As Long) As Long
    Whoops, my mistake, I posted code I was using to test different configurations. It should be
    VB Code:
    1. Public Function DLLMain(ByVal hInst As Long, ByVal fdwReason As Long, _
    2. ByVal  lpvReserved As Long) As Long

    The hInst value passed to DllMain needs to be passed as is to SetWindowsHookEx
    Code:
    HHOOK SetWindowsHookEx(      
        int idHook,
        HOOKPROC lpfn,
        HINSTANCE hMod,
        DWORD dwThreadId
    );
    it's a handle (which is a pointer) and this function needs that pointer.

    I don't know why the code is giving a breakpoint at that line. Again we don't need subclassing now so let's just disable it for the time being.

  7. #87
    Lively Member CodeBlock's Avatar
    Join Date
    May 2005
    Location
    The_Universe.Milky_Way. Solar_System.Inner_Ring. The_Earth.Asia. India.TN. Chennai. Home_Sweet_Home
    Posts
    85

    Re: Check if Application is Running Without Timer

    Ok, SetWndProcHook Works fine, and notepad stils stays on and removes hook correctly, BUT WndProc inside the DLL was never called

    What might be the reason?

    This is my DLL code
    Attached Files Attached Files

  8. #88
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Check if Application is Running Without Timer

    Did you move yor mouse over the top of notepad to generate a message? That's when it crashes for me.

    PS: It's obvious you're not a NOOB, but I have to ask.

  9. #89
    Lively Member CodeBlock's Avatar
    Join Date
    May 2005
    Location
    The_Universe.Milky_Way. Solar_System.Inner_Ring. The_Earth.Asia. India.TN. Chennai. Home_Sweet_Home
    Posts
    85

    Re: Check if Application is Running Without Timer

    Quote Originally Posted by moeur
    Did you move yor mouse over the top of notepad to generate a message? That's when it crashes for me.

    PS: It's obvious you're not a NOOB, but I have to ask.
    LOL, You got to be kidding me... I minimized, maximized, Type some message, Selected them through mouse, and did so many stuff but Notepad was stubborn that it wont crash, and the VB DLL was stubborn that it will not receive any message for the actions i did

    Is your WndProc getting called correctly?

  10. #90
    Lively Member CodeBlock's Avatar
    Join Date
    May 2005
    Location
    The_Universe.Milky_Way. Solar_System.Inner_Ring. The_Earth.Asia. India.TN. Chennai. Home_Sweet_Home
    Posts
    85

    Re: Check if Application is Running Without Timer

    Also, did u take a look at my DLL?? My DLL has the following WndProc Code:
    VB Code:
    1. Public Function SetWndProcHook(hWndVB As Long, dwThreadId As Long) As Boolean
    2.     If IsHooked Then
    3.         SetWndProcHook = False
    4.         'MsgBox "Don't hook CALLWNDPROC twice or you will be unable to unhook it."
    5.     Else
    6.         Open "DLLLog.txt" For Append As #1
    7.             Print #1, Now & " : Going to Set a New hook for dwThreadId=" & dwThreadId
    8.         Close #1
    9.  
    10.         hHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf WndProc, hInstance, dwThreadId)
    11.         If hHook = 0 Then
    12.             SetWndProcHook = False
    13.         Else
    14.             hWndCallback = hWndVB
    15.             IsHooked = True
    16.             SetWndProcHook = True
    17.         End If
    18.     End If
    19. End Function
    20.  
    21. Public Function WndProc(ByVal uCode As Long, _
    22.     ByVal wParam As Long, lParam As CWPSTRUCT) As Long
    23.  
    24.     Dim strMessage As String
    25.     Dim OutData As COPYDATASTRUCT
    26.     Dim vParam As CWPSTRUCT
    27.  
    28.     Open "DLLLog.txt" For Append As #1
    29.         Print #1, Now & " : WndProc Called: uCode=" & uCode & ", wParam=" & wParam
    30.     Close #1
    31.  
    32.         Select Case uCode
    33.        
    34.             Case HC_ACTION
    35. ''                If lParam.message = 0 Then 'just check WM_NULL messages for now
    36. ''                  strMessage = "MSG:" & Hex$(lParam.message) _
    37. ''                             & "    HWND:" & Hex(lParam.hwnd) _
    38. ''                             & "    WPARAM:" & Hex(lParam.wParam) _
    39. ''                             & "    LPARAM:" & Hex(lParam.lParam) _
    40. ''                             & "    CURRTHREAD:" & Hex(wParam)
    41. ''
    42. ''                  With OutData
    43. ''                    .lpData = StrPtr(strMessage)
    44. ''                    .dwData = 0
    45. ''                    .cbData = Len(OutData)
    46. ''                  End With
    47. ''                  SendMessage hWndCallback, WM_COPYDATA, 0, OutData
    48. ''                End If
    49.             Case Else
    50.         End Select
    51.    
    52.    
    53.     WndProc = CallNextHookEx(hHook, uCode, wParam, lParam)
    54. End Function

    In the DLLLog.txt:
    7/21/2005 4:10:56 AM : Going to Set a New hook for dwThreadId=2132
    is displayed.. but no entry is displayed for WndProc Called

    Whats the prob?

  11. #91
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Check if Application is Running Without Timer

    Just finished looking at your dll,

    The problem is that you can't put file access statements into the dllMain or the dll won't attach. This is because those libraries aren't loaded.

    Comment out those lines in DllMain and you will see Notepad crash crash crash...

    This at least tells us we are attaching the dll, but something is wrong with the WndProc routine.

  12. #92
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Check if Application is Running Without Timer

    OK, here is more info
    change WndProc to just
    VB Code:
    1. Public Function WndProc(ByVal uCode As Long, _
    2.     ByVal wParam As Long, ByVal lParam As Long) As Long
    3.     Dim i As Integer
    4.     WndProc = 0
    5. End Function
    This allows the dll to attach to Notepad and does not crash Notepad.

    Now, just add something simple and it crashes Notepad.
    VB Code:
    1. Public Function WndProc(ByVal uCode As Long, _
    2.     ByVal wParam As Long, ByVal lParam As Long) As Long
    3.     Dim i As Integer
    4.    
    5.     For i = 1 To 10
    6.     Next i
    7.    
    8.     WndProc = 0 'CallNextHookEx(hHook, uCode, wParam, lParam)
    9. End Function

    So we cannot use any VB code inside the routine. This makes sense since non of the libraries or com objects have been initialized.

  13. #93
    Lively Member CodeBlock's Avatar
    Join Date
    May 2005
    Location
    The_Universe.Milky_Way. Solar_System.Inner_Ring. The_Earth.Asia. India.TN. Chennai. Home_Sweet_Home
    Posts
    85

    Re: Check if Application is Running Without Timer

    Quote Originally Posted by moeur
    Just finished looking at your dll,

    The problem is that you can't put file access statements into the dllMain or the dll won't attach. This is because those libraries aren't loaded.

    Comment out those lines in DllMain and you will see Notepad crash crash crash...

    This at least tells us we are attaching the dll, but something is wrong with the WndProc routine.
    YUP, It does now ... lol

  14. #94
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Check if Application is Running Without Timer

    I think I've gone full circle. A while back I was trying to find out how to make a callback from one thread in C++ dll to another thread in a VB exe. Well I never solved the problem and it has something to do with initializing the com objects VB need that are stored on a per thread basis.

    Here is that thread
    http://www.vbforums.com/showthread.php?t=327589

  15. #95
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Check if Application is Running Without Timer

    I found a way to do it without using a hook at all. Instead, subclass your form and call RegisterShellHookWindow() to receive the shell notifications.

    Attached is a demo which monitors to see if Notepad is open.

    Attached Files Attached Files

  16. #96
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Check if Application is Running Without Timer

    Quote Originally Posted by penagate
    I found a way to do it without using a hook at all. Instead, subclass your form and call RegisterShellHookWindow() to receive the shell notifications.

    Attached is a demo which monitors to see if Notepad is open.
    Just read this now, very interesting! Great job

  17. #97
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Check if Application is Running Without Timer

    Hmmm... Timer, so many misconceptions. Look in my signature for Help with Timers.

    Timers are not bad. that like saying that your car is bad because it can't haul 10 tons of dirt. The right tool for the right job.

  18. #98
    New Member
    Join Date
    May 2007
    Posts
    1

    Re: Check if Application is Running Without Timer

    Quote Originally Posted by penagate
    I found a way to do it without using a hook at all. Instead, subclass your form and call RegisterShellHookWindow() to receive the shell notifications.

    Attached is a demo which monitors to see if Notepad is open.
    This code is great, can somebody please turn this into vb.net code? I am having a hard time converting.

Page 3 of 3 FirstFirst 123

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