Solved

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

Posted on 2010-11-18
5
257 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using web browser with BING 40 111
Spell Check in VB6 13 99
how to know if my Checkbox is True in VB6.0? 9 41
Embarcadero C++ Builder XE10.1 Berlin red arrow Indicator 2 20
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

22 Experts available now in Live!

Get 1:1 Help Now