CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    May 2010
    Posts
    8

    Question Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Hi,
    I have a problem in Calling Vb6 ActiveX form Dll Inside .NET Form result in Tab order work in reverse way ,and it can't go inside Frame control.
    I have found Microsoft kb 233263 article that telling about that issue and denoted that solution will be the message pump(Loop) needs to call the IsDialogMessage API.
    Actually i have saw many case but its .Net dll called from VB6 (my oppisite case) but i was unable to convert that code to Fix message Loop throught calling IsDialogMessage for Tab key from VB6 ,they calling that keybord hook ,but I have Developed that Code down , and the result is that it try to fix message loop it did reversed the tab order if i run this form from Vb6 but i cant see any effect when i call the vb6 Dll from .NET.
    What could be the problem !!!!!!!!!




    Private Const HC_ACTION = 0
    Public Const WM_NULL = &H0
    Public Const PM_REMOVE = &H1
    Public Const WM_KEYFIRST = &H100
    Public Const WM_KEYLAST = &H108
    Public Const WH_GETMESSAGE = 3


    Public hHook As Long
    Public hWindH As Long


    Public Declare Function SetWindowsHookEx Lib "user32" _
    Alias "SetWindowsHookExA" (ByVal idHook As Long, _
    ByVal lpfn As Long, _
    ByVal hmod As Long, _
    ByVal dwThreadId As Long) As Long

    Public Declare Function UnhookWindowsHookEx Lib "user32" _
    (ByVal hHook As Long) As Long

    Private Declare Function CallNextHookEx Lib "user32" _
    (ByVal hHook As Long, _
    ByVal nCode As Long, _
    ByVal wParam As Long, _
    ByRef lParam As Msg) As Long


    Public Declare Function IsDialogMessage Lib "user32" _
    Alias "IsDialogMessageA" _
    (ByVal hDlg As Long, _
    lpMsg As Msg) As Long


    Private Type KBDLLHOOKSTRUCT
    vkCode As Long
    scanCode As Long
    flags As Long
    time As Long
    dwExtraInfo As Long
    End Type

    Type Msg
    hwnd As Long
    message As Long
    wParam As Long
    lParam As Long
    time As Long
    ptX As Long
    ptY As Long
    End Type


    Public Sub HookKeyboard(ByVal FormHwd As Long)
    hHook = SetWindowsHookEx(WH_GETMESSAGE, AddressOf GetMsgProc, _
    0&, App.ThreadID)
    hWindH = FormHwd
    Call CheckHooked
    End Sub

    Public Function GetMsgProc(ByVal uCode As Long, ByVal wParam As Long, lParam As Msg) As Long
    If wParam = PM_REMOVE Then
    Select Case uCode
    Case HC_ACTION
    If lParam.message >= WM_KEYFIRST And lParam.message <= WM_KEYLAST Then
    If IsDialogMessage(hWindH, lParam) Then
    Debug.Print "Tab hooked and Call IsDialogMessage"
    lParam.message = WM_NULL
    lParam.wParam = 0
    lParam.lParam = 0
    End If
    End If
    End Select
    End If
    GetMsgProc = CallNextHookEx(hHook, uCode, wParam, lParam)
    End Function
    '----------------------------------------------------------------------------

    Public Sub UnhookKeyboard()
    If (Hooked) Then
    Call UnhookWindowsHookEx(hHook)
    End If
    End Sub

    Public Sub CheckHooked()
    If (Hooked) Then
    Debug.Print "Keyboard hooked"
    Else
    Debug.Print "Keyboard hook failed: " & err.LastDllError
    End If
    End Sub

    Private Function Hooked()
    Hooked = hHook <> 0
    End Function

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Please use &#091;CODE] tags when posting code!

    The code you posted shows hooking etc. It has nothing to do with anything, is that all code you have? Please explain better.

  3. #3
    Join Date
    May 2010
    Posts
    8

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Here we do call the HookKeyboard with a handel to window that start hook the tab key press ,
    My Form is called modeless from Activex DLL into .NET by using Showwindow() API call.
    but its not attached to .NEt parent form as it appears in task bar as a separate thread.

    Microsoft kb 233263 article that telling that issue for Dialog Modelees and denoted that solution will be the message pump(Loop) needs to call the IsDialogMessage API.
    the code below i developed should do fix message loop that work but it dose not do any thing when i call the VB6 form Inside VB.NET .
    When i try to call a Vb6 form inside VB6 project it give the same behave (tab order work in reverse and can't access frame control ) as happning in VB.NET without my code.
    here is listing ,
    if somthing not clear let me know please :

    Code:
     
    Private Sub Form_Load()
        HookKeyboard (Me.hwnd)
     End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
       UnhookKeyboard
    End Sub
    
    '---------------------------------------------KeyboardHandler.bas--------------------------------------------------
    'Define const
    Private Const HC_ACTION = 0
    Public Const WM_NULL = &H0
    Public Const PM_REMOVE = &H1
    Public Const WM_KEYFIRST = &H100
    Public Const WM_KEYLAST = &H108
    Public Const WH_GETMESSAGE = 3
    Public hHook As Long
    Public hWindH As Long
    
    
    Public Declare Function SetWindowsHookEx Lib "user32" _
      Alias "SetWindowsHookExA" (ByVal idHook As Long, _
                                 ByVal lpfn As Long, _
                                 ByVal hmod As Long, _
                                 ByVal dwThreadId As Long) As Long
    
    Public Declare Function UnhookWindowsHookEx Lib "user32" _
      (ByVal hHook As Long) As Long
                                 
                                 
    Private Declare Sub CopyMemory Lib "kernel32" _
       Alias "RtlMoveMemory" _
      (pDest As Any, _
       pSource As Any, _
       ByVal cb As Long)
         
    Private Declare Function CallNextHookEx Lib "user32" _
       (ByVal hHook As Long, _
       ByVal nCode As Long, _
       ByVal wParam As Long, _
       ByRef lParam As Msg) As Long
      
    
    Public Declare Function IsDialogMessage Lib "user32" _
                            Alias "IsDialogMessageA" _
                            (ByVal hDlg As Long, _
                            lpMsg As Msg) As Long
      
      
    Type Msg
        hwnd As Long
        message As Long
        wParam As Long
        lParam As Long
        time As Long
        ptX As Long
        ptY As Long
    End Type
    
    Public Sub HookKeyboard(ByVal FormHwd As Long)
    'Start hooking
      hHook = SetWindowsHookEx(WH_GETMESSAGE, AddressOf GetMsgProc, _
                            0&, App.ThreadID)
      hWindH = FormHwd
      Call CheckHooked
    End Sub
    
    Public Function GetMsgProc(ByVal uCode As Long, ByVal wParam As Long, lParam As Msg) As Long
    If wParam = PM_REMOVE Then
      Select Case uCode
        Case HC_ACTION
            If lParam.message >= WM_KEYFIRST And lParam.message <= WM_KEYLAST Then
                If IsDialogMessage(hWindH, lParam) Then
                   Debug.Print "Tab hooked and Call IsDialogMessage"
                  lParam.message = WM_NULL
                  lParam.wParam = 0
                  lParam.lParam = 0
                End If
            End If
        End Select
    End If
    GetMsgProc = CallNextHookEx(hHook, uCode, wParam, lParam)
    End Function
    
    Public Sub UnhookKeyboard()
      If (Hooked) Then
        Call UnhookWindowsHookEx(hHook)
      End If
    End Sub
    
      Public Sub CheckHooked()
      If (Hooked) Then
        Debug.Print "Keyboard hooked"
      Else
        Debug.Print "Keyboard hook failed: " & err.LastDllError
      End If
    End Sub
    
    Private Function Hooked()
      Hooked = hHook <> 0
    End Function

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Could you provide us with the .NET .dll file, perhaps the project?

  5. #5
    Join Date
    May 2010
    Posts
    8

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Hi HanneS,
    I did attched the vb6 project and .NEt project .
    feel free to adjust any code you like to make it run.
    Attached Files Attached Files

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Thanks, next time please try to use WinZip instead of WinRar

    OK, I opened your projects ( nice work BTW ). In the VB 6 it complains that it cannot find :

    CommonRules
    And
    CommonSchema_PRJ

    Sorry to be such a pain to complain all the time, but everything is not there we cannot get this working.

  7. #7
    Join Date
    May 2010
    Posts
    8

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Remove any unwanted dll or refrence's and comment code to make the form just showing to see how tab order behave , actually those dll was registerd at our server but i belive that you don't need them.

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    OK. You're not making it easy for us though...

    I'll have a look at it tomorrow.

  9. #9
    Join Date
    May 2010
    Posts
    8

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    please down load all attchement again and the Dll zip .
    please don't forget to register them and to change the refrence in the project.
    Attached Files Attached Files
    Last edited by dexer; June 2nd, 2010 at 05:22 AM.

  10. #10
    Join Date
    May 2010
    Posts
    8

    Lightbulb Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    I’m using showwindow() API call because it’s the only way to show modeless Form into .NET ,if you tried yourself to use the Show () function from Vb6 it will give you error similer to that “Non-modal forms cannot be displayed in this host application from an ActiveX DLL, ActiveX Control, or Property Page."”
    Refer to that : https://connect.microsoft.com/Visual...&wa=wsignin1.0
    Microsoft kb 233263 article telling that issue for Dialog Modeless and denoted that solution will be the message pump(Loop) needs to call the IsDialogMessage API.
    http://support.microsoft.com/kb/233263
    When a modeless dialog box is launched from a dynamic-link library (DLL), the TAB key and the arrow keys do not move the focus from control to control as you would expect.
    For a modeless dialog box to process a TAB key, the message pump needs to call the IsDialogMessage API.
    To work around this problem, you can use a WH_GETMESSAGE hook to capture the keystroke messages and call the IsDialogMessage API. If IsDialogMessage returns TRUE, then do not pass the message on to the message pump. Set the hook when handling WM_INITDIALOG and unset it when handling the WM_DESTROY message.

    That’s why I tried to work around the problem using hooking as Microsoft set that as a solution for the problem.
    -It’s a requirement in my Application to show all my forms as a modeless so I cannot use (Form1.Show vbModal) .

  11. #11
    Join Date
    Oct 2011
    Posts
    3

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Please post if anyone find solution for tab keys of Vb6 Activex form Dll in .NET

  12. #12
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Looks for articles by tt(n) - SENDKEYS
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  13. #13
    Join Date
    Oct 2011
    Posts
    3

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Could you please elaborate on how to use sendkeys in this scenario. In .net app,I attached sendkeys class and on form_keyup event called sendkeys.send("tab"). But it did not work. Please help me with its use in my scenario.
    Thanks

  14. #14
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Get the handle or title of a control, and set it to that. Did you try the samples he included? I had to set the second flag to FALSE to send to Notepad, after I modified the title to find to "Untitled - Notpad"
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  15. #15
    Join Date
    Oct 2011
    Posts
    3

    Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way

    Thanks for your reply. Tab order now worked for me. But I used ActiveX EXE in place of ActiveX dll. It resolved all my tab order and other UI issues.

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

Featured