A typo that cost 5 man hours and almost a re-design
-
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
. -
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
.Typos are the best errors if you're looking for some stress :laugh: Glad you got it all working.
-
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
.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.
-
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
.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
-
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
.Ouch... Take consolation in the fact it only cost 5 man hours.
-
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
.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.
-
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
.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%
-
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
.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
-
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
. -
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
.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