Link to home
Start Free TrialLog in
Avatar of dvplayltd
dvplayltdFlag for Bulgaria

asked on

How can I find which are the windows messages sends by external device ?

Hi experts!

I’m professional programmer with 10+ years in IT, but now have a new task and I need help.  I have a external hardware device, which is primary intend to be rule with DLL on C. But I use VB6 with call DLL with _stdcall conversions, it work. Almost work :-)

 I found that callback which are return from this device are not very correct. In the past I was catch these message not with call back, but with hook and detect which messages are produced from hardware which I need to rule. More, this is recommended way for VB6. Look my example code, it works fine for one other hardware device.


I’m sure it will work for this same device too. Problem is that I can’t use help from manufacturer and need to find which are the messages sending from this device. I can review final result of this device. I have some information for it, in general I need a tool to save all windows messages, then to review it for message owner (I know name of DLL)  and I’ll find what are exactly numbers.

In the example code, in fact I need WM_HARMONY , correct values for MPG_FILE_READ_COMPLETE, MPG_FILE_PLAY_COMPLETE
is known.


Please help.

Option Explicit

Private Declare Sub CopyMemoryWord Lib "kernel32" Alias "RtlMoveMemory" (Destination As Integer, ByVal Source As Long, ByVal Length As Long)


 Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
           (ByVal lpPrevWndFunc As Long, _
            ByVal hWnd As Long, _
            ByVal Msg As Long, _
            ByVal wParam As Long, _
            ByVal lParam As Long) As Long

    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
           (ByVal hWnd As Long, _
            ByVal nIndex As Long, _
            ByVal dwNewLong As Long) As Long

    Public Const GWL_WNDPROC = -4

    Public Const WM_RBUTTONUP = &H205

    Global lpPrevWndProc As Long
    Global gHW As Long

    Public Sub Hook()
        lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
                                     AddressOf WindowProc)
    End Sub

    Public Sub UnHook()
        Dim lngReturnValue As Long
        lngReturnValue = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    End Sub
    

    Function WindowProc(ByVal hw As Long, _
                        ByVal uMsg As Long, _
                        ByVal wParam As Long, _
                        ByVal lParam As Long) As Long

        
'        Dim ChNo As String
        Dim oPC As clsPlayoutChannel, ms As Long
        If uMsg = WM_HARMONY Then
          
           'ChNo = CStr(4 * HiWord(lParam) + LoWord(lParam) + 1)
           Select Case wParam
            Case MPG_FILE_READ_COMPLETE
              Set oPC = cPCs(CStr(4 * HiWord(lParam) + LoWord(lParam) + 1))
              oPC.LoadNextFile
              Exit Function
              
            Case MPG_FILE_PLAY_COMPLETE
              Set oPC = cPCs(CStr(4 * HiWord(lParam) + LoWord(lParam) + 1))
              
'              Debug.Print Now & " Different oPC.PlayingFileEnd - PerCounter = " & oPC.PlayingFileEnd - GetPerformanceCounter
              ActionOnEvent_FilePlay_Complate oPC
              

'
'            Case MPG_FILE_FRAME_STICK
'
'            Case MPG_FILE_READ_START
'
'            Case Else
            End Select
    
        Else
'          Debug.Print Now & "uMsg = " & uMsg & " wParam=" & wParam & " lParam=" & lParam
          
          WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
        End If
        
    End Function

Open in new window

Avatar of Xper4net
Xper4net
Flag of France image

Lets assume that your WM_HARMONY has been created in device by using RegisterWindowMessage,
After all known cases, just test If uMsg >= 0xC000, then use a trace or a message box to display it.
Avatar of dvplayltd

ASKER

Ahaaaa. You say that most device use code bigger than 0xC000, ?

Ok .. starting to try !
ASKER CERTIFIED SOLUTION
Avatar of Xper4net
Xper4net
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks to both of you boys.I change code like you both offer and    I believe I was able to catch messages even from this device, but again it crash, look that again values are from different thread and is not possible to be get from this way. I’ll need to find complete fidderent solution and invite you to review this new question:

https://www.experts-exchange.com/questions/26628783/Manage-VB6-callback-problem-with-external-C-DLL.html

 Again, thanks for your help!