Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / November 2008



Tip: Looking for answers? Try searching our database.

VB6: user32.dll function fails without any error. I am afraid it kills my business.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Judy Ackert - 17 Nov 2008 01:21 GMT
Hello!
I hope I am in the right newsgroup.
I have a code that relies on the user32.dll.
It uses the SendInput function. I am no SendInput newbie.

This happens quite often (for about 1 of 50 customers):

They use my application for some time, then they suddenly say "It
doesn't work anymore!".
I then send them some test applications to dig down to the problem.
And I found out that the problem is always based on the fact that
SendInput doesn't do what I want.

Yesterday I had a customer who swore to me that he didn't do anything...
he didn't install any software... nothing.

What would you do if this function doesn't do what it should?
Err.LastDLLError is 0.
Oh god, this is so stupid... I don't understand why it always worked,
and then suddenly not.
For me this problem means if I can pay my rent or not.

Public Const KEYEVENTF_KEYUP As Long = &H2
Const KEYEVENTF_KEYDOWN = &H0
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_UNICODE = &H4
Const INPUT_KEYBOARD = 1

Private Type KEYBDINPUT
      wVK As Integer
      wScan As Integer
      dwFlags As Long
      Time As Long
      dwExtraInfo As Long
End Type

Public Type INPUT_Type
      dwType As Long
      xi(0 To 23) As Byte
End Type

Public Declare Function SendInput Lib "user32.dll" (ByVal nInputs As
Long, pInputs As INPUT_Type, ByVal cbSize As Long) As Long

Public Sub SendKey(ByVal lKey As Long)
On Error Goto ErrHandler

    Dim inputevents(0 To 1) As INPUT_TYPE
    Dim keyevent As KEYBDINPUT

    With keyevent
        .wVk = 0 '/ wVK must be 0 if dwFlags contains the
KEYEVENTF_UNICODE flag
        .wScan = lKey
        .dwFlags = KEYEVENTF_KEYDOWN Or KEYEVENTF_UNICODE
        .time = 0
        .dwExtraInfo = 0
    End With
    inputevents(0).dwType = INPUT_KEYBOARD
    CopyMemory inputevents(0).xi(0), keyevent, Len(keyevent)

    With keyevent
        .wVk = 0
        .wScan = lKey
        .dwFlags = KEYEVENTF_KEYUP Or KEYEVENTF_UNICODE
        .time = 0
        .dwExtraInfo = 0
    End With
    inputevents(1).dwType = INPUT_KEYBOARD
    CopyMemory inputevents(1).xi(0), keyevent, Len(keyevent)

    Dim l&
    l = SendInput(2, inputevents(0), Len(inputevents(0)))

ErrHandler:
MsgBox "An error occured in function #392347"
End Sub

I don't understand it, and I am afraid it's killing my business if it
don't find the error.
What would you do to find the error?
expvb - 17 Nov 2008 02:55 GMT
Please post your message to news://microsoft.public.vb.winapi

Note that you don't have "Exit Sub" before ErrHandler, so the message box
would appear every time if that was the complete code.

Good luck
Judy Ackert - 17 Nov 2008 11:08 GMT
expvb schrieb:
> Please post your message to news://microsoft.public.vb.winapi
>
> Note that you don't have "Exit Sub" before ErrHandler, so the message box
> would appear every time if that was the complete code.
>
> Good luck

Yes, I know... I quickly put that in in my posting...
expvb - 17 Nov 2008 03:36 GMT
You may want to check this page:

http://vb.mvps.org/samples/project.asp?id=sendinput
Judy Ackert - 17 Nov 2008 11:09 GMT
Yes, I know this article. But it's off topic for me because the user
from yesterday used my app for months, and he is on XP.
Then the function suddenly fails...

> You may want to check this page:
>
> http://vb.mvps.org/samples/project.asp?id=sendinput
Nico Notter - 19 Nov 2008 17:03 GMT
Your code doesn't show any error trapping for bad results of
SendInput call. This is not important, it is highly
important to verify that your app could send off correctly.

You might have a look onto
http://msdn.microsoft.com/en-us/library/ms646310.aspx where
they explain the return value of this function:

"The function returns the number of events that it
successfully inserted into the keyboard or mouse input
stream. If the function returns zero, the input was already
blocked by another thread..."

If your return value is ok the problem might be far away
from this code snippet, if your return value indicates lost
events it's clear that nothing arrived at the other side,
and you might send the keystrokes again.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.