none
Ayuda con este error "CallbackOnCollectedDelegate was detected" RRS feed

  • Pregunta

  • Hola a Todos estoy tratando de que mi apicacion en vb 2010 frame work 4 desabilite las teclas  de windows, ctrl y esc, alt ytab

    consegui el codigo que les muestro en lared, y me marca el siguiente error:

     "CallbackOnCollectedDelegate was detected
    Message: A callback was made on a garbage collected delegate of type 'RMS Tech!RMS_Tech.BloqueTeclas+LowLevelKeyboardProcDelegate::Invoke'.
    This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code,
    they must be kept alive by the managed application until it is guaranteed that they will never be called."

    les  agradesco su ayuda gracias

    Public NotInheritable Class BloqueTeclas
    
        Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As LowLevelKeyboardProcDelegate, ByVal hMod As IntPtr, ByVal dwThreadId As Integer) As IntPtr
        Declare Function UnhookWindowsHookEx Lib "user32" Alias "UnhookWindowsHookEx" (ByVal hHook As IntPtr) As Boolean
        Declare Function CallNextHookEx Lib "user32" Alias "CallNextHookEx" (ByVal hHook As IntPtr, ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
        Public Delegate Function LowLevelKeyboardProcDelegate(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
        Const WH_KEYBOARD_LL As Integer = 13
    
        Structure KBDLLHOOKSTRUCT
            Dim vkCode As Integer
            Dim scanCode As Integer
            Dim flags As Integer
            Dim time As Integer
            Dim dwExtraInfo As Integer
        End Structure
        Shared intLLKey As IntPtr
        Private Shared Function LowLevelKeyboardProc(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
            Dim blnEat As Boolean = False
            Select Case wParam
                Case 256, 257, 260, 261
                    'Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key    
                    blnEat = ((lParam.vkCode = 9) AndAlso (lParam.flags = 32)) Or _
                    ((lParam.vkCode = 27) AndAlso (lParam.flags = 32)) Or _
                    ((lParam.vkCode = 27) AndAlso (lParam.flags = 0)) Or _
                    ((lParam.vkCode = 91) AndAlso (lParam.flags = 1)) Or _
                    ((lParam.vkCode = 92) AndAlso (lParam.flags = 1))
            End Select
            If blnEat = True Then
                Return 1
            Else
                Return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)
            End If
    
        End Function
    
        Public Shared Sub Show()
            BloqueTeclas.SetVisibility(True)
        End Sub
    
        Public Shared Sub Hide()
            BloqueTeclas.SetVisibility(False)
        End Sub
        Private Shared Sub SetVisibility(ByVal show As Boolean)
            Dim intLLKey1 As New IntPtr
    
            If show = False Then
                intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, IntPtr.Zero, 0)
            End If
            If show = True Then
                UnhookWindowsHookEx(intLLKey)
            End If
        End Sub
    End Class


    Alvaro

    miércoles, 19 de junio de 2013 0:17

Respuestas

Todas las respuestas