Doug Robertson
2008-03-20 15:43:01 UTC
I'm using App Verifier 3.4.0158 on a program written in VB2005 and I'm
getting a crash when using sendkeys.send.
The program keeps and encrypted list of the user's various usernames and
passwords for websites and allows them to scroll through the list and select
the pair for the website (or other program) they need to login to.
The program uses the "SetWindowsHookEx" API to hook the keyboard and watch
for two different hotkeys.
The user then starts I.E. (or some other program requiring a login) and with
my program running in the background can use the designated hotkeys to copy
and paste the username and/or password from the program's form to the
foreground application.
My program's keyboard callback routine checks the key and if its one of the
designated hotkeys, fires a timer to do the copy and paste and returns a 1.
If not one of my hotkeys it uses "CallNextHookEx" to call the next link in
the keyboard chain.
All of this seems to work OK. The problem is in the timer routine below:
______
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer2.Tick
Dim tmpstring As String
'Dim hwnd As Integer
'Dim ThreadInfo As New LPGUITHREADINFO
'Dim result As Integer
Timer2.Enabled = False
UnhookKeyboard()
'Copy the field to the clipboard. A temporary string is used because
'The direct copy function will not work if the field is defined as a
'password field.
tmpstring = txtUsername.Text
Clipboard.SetText(tmpstring)
'Now get the handle of the process with the current input focus
'ThreadInfo.cbsize = Marshal.SizeOf(ThreadInfo) 'set the
structure size
'result = GetGUIThreadInfo(hwnd, ThreadInfo) 'call with
a null hwnd will return the window the user has focused
'hwnd = ThreadInfo.hwndFocus 'This the thread with the input focus
'Now use sendmessage to the focused handle to command a paste
operation
'SendMessage(hwnd, WM_PASTE, 0, 0)
'Check that modifier keys have been released
Do
Loop While (My.Computer.Keyboard.AltKeyDown = True) Or
(My.Computer.Keyboard.ShiftKeyDown = True)
'Now send a CTRL+V to force the paste function.
SendKeys.SendWait("^v") 'wait for the ^v to be processed before
clearing the clipboard
Clipboard.Clear() 'clear the clipboard to prevent further pasting
to another program via a manual ^v
HookKeyboard()
End Sub
______
There are actually two timers - one copies from the username field and one
from the password field, but they're otherwise identical.
All this timer does is copy the text to the clipboard then send a CTRL+V to
whatever program is in the foreground.
(You'll notice some code that's been commented out. I originally was using
the API's to find the focused thread and send a WM_PASTE message to the
forground app. This worked with most apps, but for whatever reason, I.E.
seems to ignore the WM_PASTE message.)
This all works perfectly unless application verifier is running.
App verifier causes the sendkeys.send("^v") to crash the program with an
error "Program List Manger has encounterd a user-defined breakpoint"
Huh?
The app verifier log reads:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <avrf:logfile xmlns:avrf="Application Verifier">
- <avrf:logSession TimeStarted="2008-03-20 : 09:51:16" PID="4044" Version="2">
- <avrf:logEntry Time="2008-03-20 : 09:54:23" LayerName="Heaps"
StopCode="0x13" Severity="Error">
<avrf:message>First chance access violation for current stack
trace.</avrf:message>
<avrf:parameter1>0 - Invalid address causing the
exception.</avrf:parameter1>
<avrf:parameter2>7b2bb440 - Code address executing the invalid
access.</avrf:parameter2>
<avrf:parameter3>12ed34 - Exception record.</avrf:parameter3>
<avrf:parameter4>12ed50 - Context record.</avrf:parameter4>
- <avrf:stackTrace>
<avrf:trace>vrfcore!VfCoreRedirectedStopMessage+81</avrf:trace>
<avrf:trace>vfbasics!VfBasicsStopMessage+1c9</avrf:trace>
<avrf:trace>vfbasics!AVrfpCheckFirstChanceException+13a</avrf:trace>
<avrf:trace>vfbasics!AVrfpVectoredExceptionHandler+18</avrf:trace>
<avrf:trace>ntdll!RtlInitializeSListHead+9dbf</avrf:trace>
<avrf:trace>ntdll!LdrAddRefDll+1c1</avrf:trace>
<avrf:trace>ntdll!KiUserExceptionDispatcher+e</avrf:trace>
<avrf:trace>System.Windows.Forms.ni!+7b2bc986</avrf:trace>
<avrf:trace>System.Windows.Forms.ni!+7b2bca9e</avrf:trace>
</avrf:stackTrace>
</avrf:logEntry>
</avrf:logSession>
</avrf:logfile>
I've tried using my.computer.keyboard.sendkeys("^v") with exactly the same
result.
If I comment out the sendkeys.send, everything else runs fine without
causing any errors in app verifier.
I find it hard to believe that simply calling sendkeys represents a flaw in
my code - this looks to me like a problem with the verifier.
Thanks for any help or suggestions.
getting a crash when using sendkeys.send.
The program keeps and encrypted list of the user's various usernames and
passwords for websites and allows them to scroll through the list and select
the pair for the website (or other program) they need to login to.
The program uses the "SetWindowsHookEx" API to hook the keyboard and watch
for two different hotkeys.
The user then starts I.E. (or some other program requiring a login) and with
my program running in the background can use the designated hotkeys to copy
and paste the username and/or password from the program's form to the
foreground application.
My program's keyboard callback routine checks the key and if its one of the
designated hotkeys, fires a timer to do the copy and paste and returns a 1.
If not one of my hotkeys it uses "CallNextHookEx" to call the next link in
the keyboard chain.
All of this seems to work OK. The problem is in the timer routine below:
______
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer2.Tick
Dim tmpstring As String
'Dim hwnd As Integer
'Dim ThreadInfo As New LPGUITHREADINFO
'Dim result As Integer
Timer2.Enabled = False
UnhookKeyboard()
'Copy the field to the clipboard. A temporary string is used because
'The direct copy function will not work if the field is defined as a
'password field.
tmpstring = txtUsername.Text
Clipboard.SetText(tmpstring)
'Now get the handle of the process with the current input focus
'ThreadInfo.cbsize = Marshal.SizeOf(ThreadInfo) 'set the
structure size
'result = GetGUIThreadInfo(hwnd, ThreadInfo) 'call with
a null hwnd will return the window the user has focused
'hwnd = ThreadInfo.hwndFocus 'This the thread with the input focus
'Now use sendmessage to the focused handle to command a paste
operation
'SendMessage(hwnd, WM_PASTE, 0, 0)
'Check that modifier keys have been released
Do
Loop While (My.Computer.Keyboard.AltKeyDown = True) Or
(My.Computer.Keyboard.ShiftKeyDown = True)
'Now send a CTRL+V to force the paste function.
SendKeys.SendWait("^v") 'wait for the ^v to be processed before
clearing the clipboard
Clipboard.Clear() 'clear the clipboard to prevent further pasting
to another program via a manual ^v
HookKeyboard()
End Sub
______
There are actually two timers - one copies from the username field and one
from the password field, but they're otherwise identical.
All this timer does is copy the text to the clipboard then send a CTRL+V to
whatever program is in the foreground.
(You'll notice some code that's been commented out. I originally was using
the API's to find the focused thread and send a WM_PASTE message to the
forground app. This worked with most apps, but for whatever reason, I.E.
seems to ignore the WM_PASTE message.)
This all works perfectly unless application verifier is running.
App verifier causes the sendkeys.send("^v") to crash the program with an
error "Program List Manger has encounterd a user-defined breakpoint"
Huh?
The app verifier log reads:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <avrf:logfile xmlns:avrf="Application Verifier">
- <avrf:logSession TimeStarted="2008-03-20 : 09:51:16" PID="4044" Version="2">
- <avrf:logEntry Time="2008-03-20 : 09:54:23" LayerName="Heaps"
StopCode="0x13" Severity="Error">
<avrf:message>First chance access violation for current stack
trace.</avrf:message>
<avrf:parameter1>0 - Invalid address causing the
exception.</avrf:parameter1>
<avrf:parameter2>7b2bb440 - Code address executing the invalid
access.</avrf:parameter2>
<avrf:parameter3>12ed34 - Exception record.</avrf:parameter3>
<avrf:parameter4>12ed50 - Context record.</avrf:parameter4>
- <avrf:stackTrace>
<avrf:trace>vrfcore!VfCoreRedirectedStopMessage+81</avrf:trace>
<avrf:trace>vfbasics!VfBasicsStopMessage+1c9</avrf:trace>
<avrf:trace>vfbasics!AVrfpCheckFirstChanceException+13a</avrf:trace>
<avrf:trace>vfbasics!AVrfpVectoredExceptionHandler+18</avrf:trace>
<avrf:trace>ntdll!RtlInitializeSListHead+9dbf</avrf:trace>
<avrf:trace>ntdll!LdrAddRefDll+1c1</avrf:trace>
<avrf:trace>ntdll!KiUserExceptionDispatcher+e</avrf:trace>
<avrf:trace>System.Windows.Forms.ni!+7b2bc986</avrf:trace>
<avrf:trace>System.Windows.Forms.ni!+7b2bca9e</avrf:trace>
</avrf:stackTrace>
</avrf:logEntry>
</avrf:logSession>
</avrf:logfile>
I've tried using my.computer.keyboard.sendkeys("^v") with exactly the same
result.
If I comment out the sendkeys.send, everything else runs fine without
causing any errors in app verifier.
I find it hard to believe that simply calling sendkeys represents a flaw in
my code - this looks to me like a problem with the verifier.
Thanks for any help or suggestions.