Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. A typo that cost 5 man hours and almost a re-design

A typo that cost 5 man hours and almost a re-design

Scheduled Pinned Locked Moved Clever Code
c++comcsharpwinformsdesign
10 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rama Krishna Vavilala
    wrote on last edited by
    #1

    We are using .NET Windows Forms and MFC in our project for the simple reason that we did not want to rewrite the entire application. There are different ways for .NET and MFC to communicate with each other: C++/CLI, COM interop etc. However the problem happens when you show a modeless dialog box in .NET code as the tab keys don't work. The solution is to add a message filter (IMessageFilter). However for the message filter need to be invoked manually as the message loop is provided by MFC and not .NET. So this code was added and invoked from CWinApp::PreTranslateMessage:

    BOOL FilterWindowsFormsMessages(MSG * pMsg)
    {
    Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
    IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

    return (Application::FilterMessage(message)) ? TRUE : FALSE;
    

    }

    The tab keys started working but weird behavior was observed. The text boxes started repeating a keystroke many times. For example if you pressed 'A' the character 'A' appeared many times. I was working with another developer and he was equally puzzled. We almost decided to re design the piece of the application by using a dialog in MFC. Then observing in spy++ we found that 'B' appeared 66 times and so on. The exact repetition count was found out only after observing it in Spy++. We figured out that WM_KEYDOWN's repeat count was equal to the key's ASCII code value. The problem was immediately clear: wParam and the lParam messed up.

    BOOL FilterWindowsFormsMessages(MSG * pMsg)
    {
    Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
    IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

    return (Application::FilterMessage(message)) ? TRUE : FALSE;
    

    }

    The bolded text should have been: IntPtr((void*)pMsg->lParam.

    M P J J M 9 Replies Last reply
    0
    • R Rama Krishna Vavilala

      We are using .NET Windows Forms and MFC in our project for the simple reason that we did not want to rewrite the entire application. There are different ways for .NET and MFC to communicate with each other: C++/CLI, COM interop etc. However the problem happens when you show a modeless dialog box in .NET code as the tab keys don't work. The solution is to add a message filter (IMessageFilter). However for the message filter need to be invoked manually as the message loop is provided by MFC and not .NET. So this code was added and invoked from CWinApp::PreTranslateMessage:

      BOOL FilterWindowsFormsMessages(MSG * pMsg)
      {
      Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
      IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

      return (Application::FilterMessage(message)) ? TRUE : FALSE;
      

      }

      The tab keys started working but weird behavior was observed. The text boxes started repeating a keystroke many times. For example if you pressed 'A' the character 'A' appeared many times. I was working with another developer and he was equally puzzled. We almost decided to re design the piece of the application by using a dialog in MFC. Then observing in spy++ we found that 'B' appeared 66 times and so on. The exact repetition count was found out only after observing it in Spy++. We figured out that WM_KEYDOWN's repeat count was equal to the key's ASCII code value. The problem was immediately clear: wParam and the lParam messed up.

      BOOL FilterWindowsFormsMessages(MSG * pMsg)
      {
      Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
      IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

      return (Application::FilterMessage(message)) ? TRUE : FALSE;
      

      }

      The bolded text should have been: IntPtr((void*)pMsg->lParam.

      M Offline
      M Offline
      Michael Sadlon
      wrote on last edited by
      #2

      Typos are the best errors if you're looking for some stress :laugh: Glad you got it all working.

      1 Reply Last reply
      0
      • R Rama Krishna Vavilala

        We are using .NET Windows Forms and MFC in our project for the simple reason that we did not want to rewrite the entire application. There are different ways for .NET and MFC to communicate with each other: C++/CLI, COM interop etc. However the problem happens when you show a modeless dialog box in .NET code as the tab keys don't work. The solution is to add a message filter (IMessageFilter). However for the message filter need to be invoked manually as the message loop is provided by MFC and not .NET. So this code was added and invoked from CWinApp::PreTranslateMessage:

        BOOL FilterWindowsFormsMessages(MSG * pMsg)
        {
        Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
        IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

        return (Application::FilterMessage(message)) ? TRUE : FALSE;
        

        }

        The tab keys started working but weird behavior was observed. The text boxes started repeating a keystroke many times. For example if you pressed 'A' the character 'A' appeared many times. I was working with another developer and he was equally puzzled. We almost decided to re design the piece of the application by using a dialog in MFC. Then observing in spy++ we found that 'B' appeared 66 times and so on. The exact repetition count was found out only after observing it in Spy++. We figured out that WM_KEYDOWN's repeat count was equal to the key's ASCII code value. The problem was immediately clear: wParam and the lParam messed up.

        BOOL FilterWindowsFormsMessages(MSG * pMsg)
        {
        Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
        IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

        return (Application::FilterMessage(message)) ? TRUE : FALSE;
        

        }

        The bolded text should have been: IntPtr((void*)pMsg->lParam.

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Ouch - that's one nasty bug, although it's a good one to test your buffer overflow handling.:-D

        Deja View - the feeling that you've seen this post before.

        1 Reply Last reply
        0
        • R Rama Krishna Vavilala

          We are using .NET Windows Forms and MFC in our project for the simple reason that we did not want to rewrite the entire application. There are different ways for .NET and MFC to communicate with each other: C++/CLI, COM interop etc. However the problem happens when you show a modeless dialog box in .NET code as the tab keys don't work. The solution is to add a message filter (IMessageFilter). However for the message filter need to be invoked manually as the message loop is provided by MFC and not .NET. So this code was added and invoked from CWinApp::PreTranslateMessage:

          BOOL FilterWindowsFormsMessages(MSG * pMsg)
          {
          Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
          IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

          return (Application::FilterMessage(message)) ? TRUE : FALSE;
          

          }

          The tab keys started working but weird behavior was observed. The text boxes started repeating a keystroke many times. For example if you pressed 'A' the character 'A' appeared many times. I was working with another developer and he was equally puzzled. We almost decided to re design the piece of the application by using a dialog in MFC. Then observing in spy++ we found that 'B' appeared 66 times and so on. The exact repetition count was found out only after observing it in Spy++. We figured out that WM_KEYDOWN's repeat count was equal to the key's ASCII code value. The problem was immediately clear: wParam and the lParam messed up.

          BOOL FilterWindowsFormsMessages(MSG * pMsg)
          {
          Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
          IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

          return (Application::FilterMessage(message)) ? TRUE : FALSE;
          

          }

          The bolded text should have been: IntPtr((void*)pMsg->lParam.

          J Offline
          J Offline
          John R Shaw
          wrote on last edited by
          #4

          Good catch! That is the basic fallacy with message passing, that they need to be generic. It is also the strength of message passing (and C); in that generic message passing allows for a simpler handling mechanism. Every body makes mistakes, but what it cost you to find the problem is nothing compared to what it would cost you if that mechanism did not exist.

          INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

          1 Reply Last reply
          0
          • R Rama Krishna Vavilala

            We are using .NET Windows Forms and MFC in our project for the simple reason that we did not want to rewrite the entire application. There are different ways for .NET and MFC to communicate with each other: C++/CLI, COM interop etc. However the problem happens when you show a modeless dialog box in .NET code as the tab keys don't work. The solution is to add a message filter (IMessageFilter). However for the message filter need to be invoked manually as the message loop is provided by MFC and not .NET. So this code was added and invoked from CWinApp::PreTranslateMessage:

            BOOL FilterWindowsFormsMessages(MSG * pMsg)
            {
            Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
            IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

            return (Application::FilterMessage(message)) ? TRUE : FALSE;
            

            }

            The tab keys started working but weird behavior was observed. The text boxes started repeating a keystroke many times. For example if you pressed 'A' the character 'A' appeared many times. I was working with another developer and he was equally puzzled. We almost decided to re design the piece of the application by using a dialog in MFC. Then observing in spy++ we found that 'B' appeared 66 times and so on. The exact repetition count was found out only after observing it in Spy++. We figured out that WM_KEYDOWN's repeat count was equal to the key's ASCII code value. The problem was immediately clear: wParam and the lParam messed up.

            BOOL FilterWindowsFormsMessages(MSG * pMsg)
            {
            Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
            IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

            return (Application::FilterMessage(message)) ? TRUE : FALSE;
            

            }

            The bolded text should have been: IntPtr((void*)pMsg->lParam.

            J Offline
            J Offline
            Jeffrey Walton
            wrote on last edited by
            #5

            Ouch... Take consolation in the fact it only cost 5 man hours.

            1 Reply Last reply
            0
            • R Rama Krishna Vavilala

              We are using .NET Windows Forms and MFC in our project for the simple reason that we did not want to rewrite the entire application. There are different ways for .NET and MFC to communicate with each other: C++/CLI, COM interop etc. However the problem happens when you show a modeless dialog box in .NET code as the tab keys don't work. The solution is to add a message filter (IMessageFilter). However for the message filter need to be invoked manually as the message loop is provided by MFC and not .NET. So this code was added and invoked from CWinApp::PreTranslateMessage:

              BOOL FilterWindowsFormsMessages(MSG * pMsg)
              {
              Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
              IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

              return (Application::FilterMessage(message)) ? TRUE : FALSE;
              

              }

              The tab keys started working but weird behavior was observed. The text boxes started repeating a keystroke many times. For example if you pressed 'A' the character 'A' appeared many times. I was working with another developer and he was equally puzzled. We almost decided to re design the piece of the application by using a dialog in MFC. Then observing in spy++ we found that 'B' appeared 66 times and so on. The exact repetition count was found out only after observing it in Spy++. We figured out that WM_KEYDOWN's repeat count was equal to the key's ASCII code value. The problem was immediately clear: wParam and the lParam messed up.

              BOOL FilterWindowsFormsMessages(MSG * pMsg)
              {
              Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
              IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

              return (Application::FilterMessage(message)) ? TRUE : FALSE;
              

              }

              The bolded text should have been: IntPtr((void*)pMsg->lParam.

              M Offline
              M Offline
              Matthew Faithfull
              wrote on last edited by
              #6

              Well spotted. I once spent 10 working days looking for a comma, only I did't know I was looking for a comma, in 8000 lines of C++ source code. It's the closest I've ever got to going mad, loosing it all together and never getting it back together again. It was a complex for loop declaration and , had been used instead of a ; screwing up the evaluation order of some horrible expression if I remeber rightly. Doesn't look so bad? Try it on a 15" monitor :((. It's amazing I'm not quite blind yet. I'd post the code but I no longer have access to it (previous job). A true classic typo horror though :)

              Nothing is exactly what it seems but everything with seems can be unpicked.

              1 Reply Last reply
              0
              • R Rama Krishna Vavilala

                We are using .NET Windows Forms and MFC in our project for the simple reason that we did not want to rewrite the entire application. There are different ways for .NET and MFC to communicate with each other: C++/CLI, COM interop etc. However the problem happens when you show a modeless dialog box in .NET code as the tab keys don't work. The solution is to add a message filter (IMessageFilter). However for the message filter need to be invoked manually as the message loop is provided by MFC and not .NET. So this code was added and invoked from CWinApp::PreTranslateMessage:

                BOOL FilterWindowsFormsMessages(MSG * pMsg)
                {
                Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
                IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

                return (Application::FilterMessage(message)) ? TRUE : FALSE;
                

                }

                The tab keys started working but weird behavior was observed. The text boxes started repeating a keystroke many times. For example if you pressed 'A' the character 'A' appeared many times. I was working with another developer and he was equally puzzled. We almost decided to re design the piece of the application by using a dialog in MFC. Then observing in spy++ we found that 'B' appeared 66 times and so on. The exact repetition count was found out only after observing it in Spy++. We figured out that WM_KEYDOWN's repeat count was equal to the key's ASCII code value. The problem was immediately clear: wParam and the lParam messed up.

                BOOL FilterWindowsFormsMessages(MSG * pMsg)
                {
                Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
                IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

                return (Application::FilterMessage(message)) ? TRUE : FALSE;
                

                }

                The bolded text should have been: IntPtr((void*)pMsg->lParam.

                M Offline
                M Offline
                Member 96
                wrote on last edited by
                #7

                This is almost a picture perfect case study why c# is so much more efficient for getting things done than c++. I've written a *lot* of c++ code but after working for a couple of years in c# exclusively when I look back on your code I just glaze over and can't believe I had to pick through that garbage for so many years. I'm not saying typos don't happen in every language but the low readability of c++ leads to this sort of problem quite easily.


                "110%" - it's the new 70%

                1 Reply Last reply
                0
                • R Rama Krishna Vavilala

                  We are using .NET Windows Forms and MFC in our project for the simple reason that we did not want to rewrite the entire application. There are different ways for .NET and MFC to communicate with each other: C++/CLI, COM interop etc. However the problem happens when you show a modeless dialog box in .NET code as the tab keys don't work. The solution is to add a message filter (IMessageFilter). However for the message filter need to be invoked manually as the message loop is provided by MFC and not .NET. So this code was added and invoked from CWinApp::PreTranslateMessage:

                  BOOL FilterWindowsFormsMessages(MSG * pMsg)
                  {
                  Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
                  IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

                  return (Application::FilterMessage(message)) ? TRUE : FALSE;
                  

                  }

                  The tab keys started working but weird behavior was observed. The text boxes started repeating a keystroke many times. For example if you pressed 'A' the character 'A' appeared many times. I was working with another developer and he was equally puzzled. We almost decided to re design the piece of the application by using a dialog in MFC. Then observing in spy++ we found that 'B' appeared 66 times and so on. The exact repetition count was found out only after observing it in Spy++. We figured out that WM_KEYDOWN's repeat count was equal to the key's ASCII code value. The problem was immediately clear: wParam and the lParam messed up.

                  BOOL FilterWindowsFormsMessages(MSG * pMsg)
                  {
                  Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
                  IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

                  return (Application::FilterMessage(message)) ? TRUE : FALSE;
                  

                  }

                  The bolded text should have been: IntPtr((void*)pMsg->lParam.

                  M Offline
                  M Offline
                  Marc Clifton
                  wrote on last edited by
                  #8

                  Funny, I saw the problem in 10 seconds. I guess I got bit by that bug a long time ago but don't remember. Marc

                  Thyme In The Country
                  Interacx
                  My Blog

                  1 Reply Last reply
                  0
                  • R Rama Krishna Vavilala

                    We are using .NET Windows Forms and MFC in our project for the simple reason that we did not want to rewrite the entire application. There are different ways for .NET and MFC to communicate with each other: C++/CLI, COM interop etc. However the problem happens when you show a modeless dialog box in .NET code as the tab keys don't work. The solution is to add a message filter (IMessageFilter). However for the message filter need to be invoked manually as the message loop is provided by MFC and not .NET. So this code was added and invoked from CWinApp::PreTranslateMessage:

                    BOOL FilterWindowsFormsMessages(MSG * pMsg)
                    {
                    Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
                    IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

                    return (Application::FilterMessage(message)) ? TRUE : FALSE;
                    

                    }

                    The tab keys started working but weird behavior was observed. The text boxes started repeating a keystroke many times. For example if you pressed 'A' the character 'A' appeared many times. I was working with another developer and he was equally puzzled. We almost decided to re design the piece of the application by using a dialog in MFC. Then observing in spy++ we found that 'B' appeared 66 times and so on. The exact repetition count was found out only after observing it in Spy++. We figured out that WM_KEYDOWN's repeat count was equal to the key's ASCII code value. The problem was immediately clear: wParam and the lParam messed up.

                    BOOL FilterWindowsFormsMessages(MSG * pMsg)
                    {
                    Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
                    IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

                    return (Application::FilterMessage(message)) ? TRUE : FALSE;
                    

                    }

                    The bolded text should have been: IntPtr((void*)pMsg->lParam.

                    F Offline
                    F Offline
                    f2
                    wrote on last edited by
                    #9

                    we face the same problem when we use modeless in regular dll with mfc application. if we use mfc extention dll then is ok. we ended up by adding filtering message and OnIdle.

                    from, -= aLbert =-

                    1 Reply Last reply
                    0
                    • R Rama Krishna Vavilala

                      We are using .NET Windows Forms and MFC in our project for the simple reason that we did not want to rewrite the entire application. There are different ways for .NET and MFC to communicate with each other: C++/CLI, COM interop etc. However the problem happens when you show a modeless dialog box in .NET code as the tab keys don't work. The solution is to add a message filter (IMessageFilter). However for the message filter need to be invoked manually as the message loop is provided by MFC and not .NET. So this code was added and invoked from CWinApp::PreTranslateMessage:

                      BOOL FilterWindowsFormsMessages(MSG * pMsg)
                      {
                      Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
                      IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

                      return (Application::FilterMessage(message)) ? TRUE : FALSE;
                      

                      }

                      The tab keys started working but weird behavior was observed. The text boxes started repeating a keystroke many times. For example if you pressed 'A' the character 'A' appeared many times. I was working with another developer and he was equally puzzled. We almost decided to re design the piece of the application by using a dialog in MFC. Then observing in spy++ we found that 'B' appeared 66 times and so on. The exact repetition count was found out only after observing it in Spy++. We figured out that WM_KEYDOWN's repeat count was equal to the key's ASCII code value. The problem was immediately clear: wParam and the lParam messed up.

                      BOOL FilterWindowsFormsMessages(MSG * pMsg)
                      {
                      Message message = Message::Create(IntPtr(pMsg->hwnd), int(pMsg->message),
                      IntPtr((void*)pMsg->wParam), IntPtr((void*)pMsg->wParam));

                      return (Application::FilterMessage(message)) ? TRUE : FALSE;
                      

                      }

                      The bolded text should have been: IntPtr((void*)pMsg->lParam.

                      S Offline
                      S Offline
                      Sathesh Sakthivel
                      wrote on last edited by
                      #10

                      Quite Funny i ahve got the Bug after seeing the code. i think that i got this probelm while i was coding on this a year before.

                      Regards, Satips.:rose: Don't walk in front of me, I may not follow; Don't walk behind me, I may not lead; Walk beside me, and just be my friend. - Albert Camus

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups