Principales respuestas
Ayuda con este error "CallbackOnCollectedDelegate was detected"

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
Respuestas
-
Perdona...haz esto por favor
Private KeyboardHookProcedure As Win32.HookProc KeyboardHookProcedure = New Win32.HookProc(AddressOf LowLevelKeyboardProc) intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, Marshal.GetHINSTANCE(Reflection.Assembly.GetExecutingAssembly().GetModules()(0)), 0)
O revisa http://www.colinneller.com/blog/PermaLink,guid,2838f59a-f4af-4c95-a322-b9ee5918a39c.aspxSi se solucionó tu consulta no olvides marcar la respuesta. Si te ayudó vótala como útil. Saludos
- Marcado como respuesta Alvaro Zubia jueves, 20 de junio de 2013 2:47
Todas las respuestas
-
intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, New LowLevelKeyboardProcDelegate( LowLevelKeyboardProc), IntPtr.Zero, 0)
debes instanciar un dlegado LowLevelKeyboardProcDelegate...
espero funcione
Si se solucionó tu consulta no olvides marcar la respuesta. Si te ayudó vótala como útil. Saludos
- Editado Sergio Parra miércoles, 19 de junio de 2013 12:05 especificar solucion
-
-
Perdona...haz esto por favor
Private KeyboardHookProcedure As Win32.HookProc KeyboardHookProcedure = New Win32.HookProc(AddressOf LowLevelKeyboardProc) intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, Marshal.GetHINSTANCE(Reflection.Assembly.GetExecutingAssembly().GetModules()(0)), 0)
O revisa http://www.colinneller.com/blog/PermaLink,guid,2838f59a-f4af-4c95-a322-b9ee5918a39c.aspxSi se solucionó tu consulta no olvides marcar la respuesta. Si te ayudó vótala como útil. Saludos
- Marcado como respuesta Alvaro Zubia jueves, 20 de junio de 2013 2:47
-