Debug and Release builds behave differently (msvc++6)

Started by
1 comment, last by tapper 20 years, 3 months ago
I''m using the following code to translate the virtual key code stored in wParam to the corresponding ascii character and store it in the variable AsciiChar:

LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  if (msg==WM_KEYDOWN)
  {
    unsigned char KeyState[256];
    unsigned short Char;
    unsigned char AsciiChar;

    if (GetKeyboardState(KeyState))
    {
      ToAscii(wParam, NULL, KeyState, &Char, 0);
      AsciiChar = (char) Char;

    //

    // Some code here

    //

    }
  }
}
If the active configuration is set to "Debug" everything works fine. But if I change it to "Release" and try to press the shift key, the value stored in AsciiChar is the previous key pressed (i. e. if I press ''A'' and then the shift key I get another ''A''). Why does GetKeyboardState() return different values on the different builds? I''m kind of new to programming so I have no idea what all the compiler switches does. Maybe someone can help me?
Advertisement
For normal keys, you should respond to the WM_CHAR message. WM_KEYDOWN is typically reserved for handling cursor keys and function keys.

I''m not sure why you get different behavior in debug vs release mode, but switching to WM_CHAR should solve your problem.
Thanks, works like a charm now!

This topic is closed to new replies.

Advertisement