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
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
Re: Check if Application is Running Without Timer
Quote:
'MISSING: Debug Object for AddressOf Subclassing'
Just remove that from the reference, it isn't needed.
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.. :p
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:
Public Function DLLMain([hl]hInst As Long[/hl], ByVal fdwReason As Long, _
lpvReserved As Long) As Long
which is ByRef.. What are you trying to tell?? You seem to contradict your own code :confused:
Anyway, i will be back with the working code of your Notepad Hook.
1 Attachment(s)
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:
#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:
'subclass this form to receive callback messages
If Not SubClass.Enable(Me.hwnd) Then
MsgBox "Subclassing Failed"
Exit Sub
End If
Re: Check if Application is Running Without Timer
Quote:
VB Code:
Public Function DLLMain(hInst As Long, ByVal fdwReason As Long, _
lpvReserved As Long) As Long
Whoops, my mistake, I posted code I was using to test different configurations. It should be
VB Code:
Public Function DLLMain(ByVal hInst As Long, ByVal fdwReason As Long, _
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.
1 Attachment(s)
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
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.:)
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 :p
Is your WndProc getting called correctly?
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:
Public Function SetWndProcHook(hWndVB As Long, dwThreadId As Long) As Boolean
If IsHooked Then
SetWndProcHook = False
'MsgBox "Don't hook CALLWNDPROC twice or you will be unable to unhook it."
Else
Open "DLLLog.txt" For Append As #1
Print #1, Now & " : Going to Set a New hook for dwThreadId=" & dwThreadId
Close #1
hHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf WndProc, hInstance, dwThreadId)
If hHook = 0 Then
SetWndProcHook = False
Else
hWndCallback = hWndVB
IsHooked = True
SetWndProcHook = True
End If
End If
End Function
Public Function WndProc(ByVal uCode As Long, _
ByVal wParam As Long, lParam As CWPSTRUCT) As Long
Dim strMessage As String
Dim OutData As COPYDATASTRUCT
Dim vParam As CWPSTRUCT
Open "DLLLog.txt" For Append As #1
Print #1, Now & " : WndProc Called: uCode=" & uCode & ", wParam=" & wParam
Close #1
Select Case uCode
Case HC_ACTION
'' If lParam.message = 0 Then 'just check WM_NULL messages for now
'' strMessage = "MSG:" & Hex$(lParam.message) _
'' & " HWND:" & Hex(lParam.hwnd) _
'' & " WPARAM:" & Hex(lParam.wParam) _
'' & " LPARAM:" & Hex(lParam.lParam) _
'' & " CURRTHREAD:" & Hex(wParam)
''
'' With OutData
'' .lpData = StrPtr(strMessage)
'' .dwData = 0
'' .cbData = Len(OutData)
'' End With
'' SendMessage hWndCallback, WM_COPYDATA, 0, OutData
'' End If
Case Else
End Select
WndProc = CallNextHookEx(hHook, uCode, wParam, lParam)
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?
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.
Re: Check if Application is Running Without Timer
OK, here is more info
change WndProc to just
VB Code:
Public Function WndProc(ByVal uCode As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Dim i As Integer
WndProc = 0
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:
Public Function WndProc(ByVal uCode As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Dim i As Integer
For i = 1 To 10
Next i
WndProc = 0 'CallNextHookEx(hHook, uCode, wParam, lParam)
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.
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 :p
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
1 Attachment(s)
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.
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
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.
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.