Solved

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

Posted on 2010-11-18
5
256 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
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Xper4net
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now