Click here to Skip to main content
15,915,501 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Socket error Pin
Dave Kreskowiak1-Jul-10 12:41
mveDave Kreskowiak1-Jul-10 12:41 
QuestionWhy is it so hard to set button text for DataGridViewButtonColumn button cell Pin
Andraw Tang1-Jul-10 6:27
Andraw Tang1-Jul-10 6:27 
AnswerRe: Why is it so hard to set button text for DataGridViewButtonColumn button cell Pin
Andraw Tang1-Jul-10 6:41
Andraw Tang1-Jul-10 6:41 
AnswerRe: Why is it so hard to set button text for DataGridViewButtonColumn button cell Pin
Scubapro1-Jul-10 21:09
Scubapro1-Jul-10 21:09 
GeneralRe: Why is it so hard to set button text for DataGridViewButtonColumn button cell Pin
Andraw Tang2-Jul-10 3:21
Andraw Tang2-Jul-10 3:21 
QuestionMulti threading and garbage collected problem using RegisterShellHook and SetWindowLong API. Pin
Аslam Iqbal1-Jul-10 0:36
professionalАslam Iqbal1-Jul-10 0:36 
AnswerRe: Multi threading and garbage collected problem using RegisterShellHook and SetWindowLong API. Pin
Luc Pattyn1-Jul-10 1:49
sitebuilderLuc Pattyn1-Jul-10 1:49 
QuestionRe: Multi threading and garbage collected problem using RegisterShellHook and SetWindowLong API. Pin
Аslam Iqbal2-Jul-10 9:58
professionalАslam Iqbal2-Jul-10 9:58 
"I do have similar functionality implemented in C#, without using any shell hooks"
Yeah you are right. I used shell hooks to monitor processes or forms.
Here is my simplyfied code:

Public Class HOOK_RMV_DEVICE
    Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Integer, _
           ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As WndProc) As Integer

    Private Shadows Delegate Function WndProc(ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

    Private Const GWL_WNDPROC = -4
    Private IsHooked As Boolean, lpPrevWndProc As Integer, WindowHandler As Integer
    '
    Private Const wMsg_REMOVABLE_DEVICE = 537
    Private Const wParam_REMOVABLE_DEVICE_INSERTED = 32768
    Private Const wParam_REMOVABLE_DEVICE_REMOVED = 32772

    Public Function Hook() As Boolean
        If IsHooked Then
            Return False
        Else
            lpPrevWndProc = SetWindowLong(WindowHandler, GWL_WNDPROC, AddressOf WindowProc)
            IsHooked = True
            Return True
        End If
    End Function
    Public Sub Unhook()
        Dim temp As Long
        temp = SetWindowLong(WindowHandler, GWL_WNDPROC, lpPrevWndProc)
        IsHooked = False
    End Sub

    Function WindowProc(ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        Dim e As New ShellHookEventArgs
        e.hWnd = hWnd
        e.wMsg = wMsg
        e.wParam = wParam
        e.lParam = lParam
        e.REMOVABLE_DEVICE_INFO = ShellHookEventArgs.REMOVABLE_DEVICE.NONE

        If wMsg = wMsg_REMOVABLE_DEVICE Then
            If wParam = wParam_REMOVABLE_DEVICE_INSERTED Then
                e.REMOVABLE_DEVICE_INFO = ShellHookEventArgs.REMOVABLE_DEVICE.INSERTED
                RaiseEvent Removable_Device(Me, e)
            ElseIf wParam = wParam_REMOVABLE_DEVICE_REMOVED Then
                e.REMOVABLE_DEVICE_INFO = ShellHookEventArgs.REMOVABLE_DEVICE.REMOVED
                RaiseEvent Removable_Device(Me, e)
            End If
        Else
            'e.TempMsg = "hwnd=" & hWnd & ", wmsg=" & wMsg & ", wparam= " & wParam & ", lparam=" & lParam
            'RaiseEvent Removable_Device(Me, e)
        End If
        WindowProc = CallWindowProc(lpPrevWndProc, hWnd, wMsg, wParam, lParam)
    End Function

    Public Event Removable_Device(ByVal sender As Object, ByVal e As ShellHookEventArgs)

    Class ShellHookEventArgs
        Inherits System.EventArgs
        Public Enum REMOVABLE_DEVICE
            NONE = 0
            INSERTED = 1
            REMOVED = 2
        End Enum
        Public hWnd, wMsg, wParam, lParam As Integer
        Public REMOVABLE_DEVICE_INFO As REMOVABLE_DEVICE
        Friend TempMsg As String
    End Class

    Public Sub New(ByVal WindowHandler As Integer)
        Me.WindowHandler = WindowHandler
    End Sub
    Public Sub New()
        Dim tmp As New Form
        WindowHandler = tmp.Handle
     End Sub
End Class

This Codes also create that same error.
Can you plz give some solution more than you gave before?
I'm not a good programmer and very week in C#. I need something details.
AnswerRe: Multi threading and garbage collected problem using RegisterShellHook and SetWindowLong API. Pin
Luc Pattyn2-Jul-10 10:38
sitebuilderLuc Pattyn2-Jul-10 10:38 
GeneralRe: Multi threading and garbage collected problem using RegisterShellHook and SetWindowLong API. Pin
Аslam Iqbal2-Jul-10 10:43
professionalАslam Iqbal2-Jul-10 10:43 
GeneralRe: Multi threading and garbage collected problem using RegisterShellHook and SetWindowLong API. Pin
Luc Pattyn2-Jul-10 11:32
sitebuilderLuc Pattyn2-Jul-10 11:32 
Questionshare and unshare folder Pin
mehrnoosh30-Jun-10 18:27
mehrnoosh30-Jun-10 18:27 
AnswerRe: share and unshare folder Pin
Dave Kreskowiak30-Jun-10 18:37
mveDave Kreskowiak30-Jun-10 18:37 
GeneralRe: share and unshare folder Pin
mehrnoosh30-Jun-10 21:54
mehrnoosh30-Jun-10 21:54 
GeneralRe: share and unshare folder Pin
Alan N30-Jun-10 22:32
Alan N30-Jun-10 22:32 
GeneralRe: share and unshare folder Pin
Dave Kreskowiak1-Jul-10 2:16
mveDave Kreskowiak1-Jul-10 2:16 
QuestionHow can I detect child form close action in VB.NET 2005 Pin
Andraw Tang30-Jun-10 9:19
Andraw Tang30-Jun-10 9:19 
AnswerRe: How can I detect child form close action in VB.NET 2005 Pin
Dave Kreskowiak30-Jun-10 9:31
mveDave Kreskowiak30-Jun-10 9:31 
GeneralRe: How can I detect child form close action in VB.NET 2005 Pin
Andraw Tang30-Jun-10 9:40
Andraw Tang30-Jun-10 9:40 
GeneralRe: How can I detect child form close action in VB.NET 2005 Pin
Dave Kreskowiak30-Jun-10 12:39
mveDave Kreskowiak30-Jun-10 12:39 
GeneralRe: How can I detect child form close action in VB.NET 2005 Pin
Andraw Tang1-Jul-10 3:32
Andraw Tang1-Jul-10 3:32 
GeneralRe: How can I detect child form close action in VB.NET 2005 Pin
Dave Kreskowiak1-Jul-10 3:42
mveDave Kreskowiak1-Jul-10 3:42 
GeneralRe: How can I detect child form close action in VB.NET 2005 Pin
Andraw Tang1-Jul-10 3:59
Andraw Tang1-Jul-10 3:59 
GeneralRe: How can I detect child form close action in VB.NET 2005 Pin
Andraw Tang1-Jul-10 4:03
Andraw Tang1-Jul-10 4:03 
AnswerRe: How can I detect child form close action in VB.NET 2005 Pin
William Winner30-Jun-10 9:38
William Winner30-Jun-10 9:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.