Solved

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

Posted on 2010-11-18
5
260 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:dvplayltd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Xper4net
ID: 34162806
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.
0
 

Author Comment

by:dvplayltd
ID: 34162956
Ahaaaa. You say that most device use code bigger than 0xC000, ?

Ok .. starting to try !
0
 
LVL 5

Accepted Solution

by:
Xper4net earned 250 total points
ID: 34163031
Some more explainations: when you don't use standard Window messages, the good practice is to require a window message registration by calling RegisterWindowMessage.
It returns a message in a range greater than 0xC000 and lower that 0xFFFF.

Otherwise, they can use messages starting from WM_USER (0x0400). In this case, you can test
If (uMsg >= 0x04000)

Hope that it could help.
0
 
LVL 29

Assisted Solution

by:nffvrxqgrcfqvvc
nffvrxqgrcfqvvc earned 250 total points
ID: 34163476
Great detail xper4net!

This might be a more difficult to figure out depending on how that device uses the message. You won't get the message value in your application unless the device sends that message directly to your window or it broadcasts to all top level windows. If the device comes with it's own software it might register it's window handle with the device and that device might send messages to the software if so you could use Spy++ to check which messages that software is receiving. If the device doesn't broadcast im afraid all you will get in your WndProc() is standard windows messages and top level broadcasts not related to the device.

0
 

Author Closing Comment

by:dvplayltd
ID: 34179682
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:

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_26628783.html

 Again, thanks for your help!
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question