Discussion:
app verifier and sendkeys
(too old to reply)
Doug Robertson
2008-03-20 15:43:01 UTC
Permalink
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.
Doug Robertson
2008-03-20 19:07:12 UTC
Permalink
More info:

When running in the debugger (and with the app verifier disabled), I get the
following when the first hotkey is pressed:
_____
ModLoad: 20000000 202c5000 C:\WINDOWS\system32\xpsp2res.dll
ModLoad: 64890000 6498c000
C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Configuration\eee9b48577689e92db5a7b5c5de98d9b\System.Configuration.ni.dll
ModLoad: 637a0000 63d28000
C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\c98cb65a79cfccb44ea727ebe4593ede\System.Xml.ni.dll
(e34.654): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000000 ebx=022e303c ecx=00000000 edx=7b475a60 esi=0012f00c edi=013322b4
eip=7b2bb440 esp=0012efec ebp=0012f02c iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010246
*** WARNING: Unable to verify checksum for
C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Windows.Forms\3d8c79c45aa674e43f075e2e66b8caf5\System.Windows.Forms.ni.dll
*** ERROR: Module load completed but symbols could not be loaded for
C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Windows.Forms\3d8c79c45aa674e43f075e2e66b8caf5\System.Windows.Forms.ni.dll
System_Windows_Forms_ni+0x2eb440:
7b2bb440 3909 cmp dword ptr [ecx],ecx
ds:0023:00000000=????????
_______

If I "go" from here the program continues and - here's the weird part (to me
anyway) - all subsequent hotkeys function correctly without generating any
errors.

I've tried putting a try-catch around the offending sendkeys statement and
discovered that NO EXCEPTION IS PRESENTED TO MY CODE.

If the debugger and the app verifier are not used (i.e. I just run the
program), the first hotkey seems to work fine and again, no exception seems
to be generated.
Post by Doug Robertson
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.
______
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?
<?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.
Loading...