Results 1 to 3 of 3

Thread: Error With API call

  1. #1

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228

    Question Error With API call

    I Have the following code:

    Public Declare Function keybd_event Lib "user32" (ByVal bVk _
    As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
    ByVal dwExtraInfo As Long)

    Public Sub ScreenCapture()
    keybd_event vbKeySnapshot, 1, 0, 0
    End Sub

    I AM GETTING THE FOLLOWING ERROR:

    Bad DLL Calling Convention (Error 49)

    Does anyone know why???? ..... as far as i know, I am calling the function correctly..... (i have also tried:
    Call keybd_event (vbKeySnapshot, 1, 0 ,0) but it gives the same error!)
    To protect time is to protect everything...

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    see if this example works for you
    VB Code:
    1. Const VK_H = 72
    2. Const VK_E = 69
    3. Const VK_L = 76
    4. Const VK_O = 79
    5. Const KEYEVENTF_EXTENDEDKEY = &H1
    6. Const KEYEVENTF_KEYUP = &H2
    7. Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    8. Private Sub Form_KeyPress(KeyAscii As Integer)
    9.     'Print the key on the form
    10.     Me.Print Chr$(KeyAscii);
    11. End Sub
    12. Private Sub Form_Paint()
    13.     'Clear the form
    14.     Me.Cls
    15.     keybd_event VK_H, 0, 0, 0   ' press H
    16.     keybd_event VK_H, 0, KEYEVENTF_KEYUP, 0   ' release H
    17.     keybd_event VK_E, 0, 0, 0  ' press E
    18.     keybd_event VK_E, 0, KEYEVENTF_KEYUP, 0  ' release E
    19.     keybd_event VK_L, 0, 0, 0  ' press L
    20.     keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0  ' release L
    21.     keybd_event VK_L, 0, 0, 0  ' press L
    22.     keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0  ' release L
    23.     keybd_event VK_O, 0, 0, 0  ' press O
    24.     keybd_event VK_O, 0, KEYEVENTF_KEYUP, 0  ' release O
    25. End Sub

  3. #3
    Junior Member
    Join Date
    Nov 2001
    Location
    Netherlands
    Posts
    22
    The error is generated by VB. VB just knows that your code never works. You might change the 0 in 0& or ByVal 0 or ByVal 0&. The & is normally never used in VB anymore, but forces a value to be Long, not integer. It's needed sometimes. Hopes this does the trick.
    Yet Another Perl Programmer



    Working with the Windows 32 API
    Test my carrier game
    X-Programming Forums (members and testers wanted!)

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