Archived

This topic is now archived and is closed to further replies.

tapper

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

Recommended Posts

tapper    122
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?

Share this post


Link to post
Share on other sites
Dave Hunt    4872
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.

Share this post


Link to post
Share on other sites