Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-11-18
5
Medium Priority
?
263 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 1000 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

661 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