Handmade Hero»Forums»Code
Joshua T Bills
3 posts
Day 002 - OutputDebugString: identifier not found
Hello all,
Thank you in advance for all help. I am new to the series, following along using CodeBlocks as me editor, but compiling the same way as the videos, using command line and VC CL. I keep getting errors saying:
error C3861: 'OutputDebugString': identifier not found

I googled this, as well as searched these forums but could not find an answer. I tried changing my include from windows.h to winbase.h, but that just introduced way more errors.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
#include <windows.h>

LRESULT CALLBACK
Win32Procedure( HWND _window,
                UINT _message,
                WPARAM _wParam,
                LPARAM _lParam )
{
   LRESULT result = 0;

   switch( _message )
   {
      case WM_SIZE:
      {
         OutputDebugStr( "WM_SIZE\n" );
      } break;

      case WM_DESTROY:
      {
         OutputDebugStr( "WM_DESTROY\n" );
      } break;

      case WM_ACTIVATEAPP:
      {
         OutputDebugStr( "WM_ACTIVEAPP\n" );
      } break;

      case WM_CLOSE:
      {
         OutputDebugStr( "WM_CLOSE\n" );
      } break;

      default:
      {
         result = DefWindowProc( _window, _message, _wParam, _lParam );
      } break;
   }

   return result;
}

int CALLBACK
WinMain( HINSTANCE _instance,
         HINSTANCE _prevInstance,
         LPSTR _commandString,
         int _commandShow )
{
   TCHAR windowName[] = "Handmade";

   WNDCLASS windowClass = {};
   windowClass.cbClsExtra = 0;
   windowClass.cbWndExtra = 0;
   windowClass.hbrBackground = 0;
   windowClass.hCursor = LoadCursor( NULL, IDC_ARROW );
   windowClass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
   windowClass.hInstance = _instance;
   windowClass.lpfnWndProc = Win32Procedure;
   windowClass.lpszClassName = windowName;
   windowClass.lpszMenuName = 0;
   windowClass.style = CS_HREDRAW | CS_VREDRAW;

   if( !RegisterClass( &windowClass ) )
   {
      MessageBox( NULL, TEXT( "Windows failed to register window." ), windowName, MB_ICONERROR );

      return -1;
   }

   HWND window = nullptr;
   window = CreateWindowEx( 0, windowClass.lpszClassName,
                            windowClass.lpszClassName,
                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                            CW_USEDEFAULT, CW_USEDEFAULT,
                            CW_USEDEFAULT, CW_USEDEFAULT,
                            0, 0,
                            _instance, 0 );

   if( window == nullptr )
   {
      MessageBox( NULL, TEXT( "Windows failed to create window." ), windowName, MB_ICONERROR );

      return -2;
   }

   for(;;)
   {
      MSG message;
      BOOL messageResult = GetMessage( &message, 0, 0, 0 );
      if( messageResult > 0 )
      {
         TranslateMessage( &message );
         DispatchMessage( &message );
      }
      else
      {
         break;
      }
   }

   return 0;
}


I am assuming this must be a compiler error? The only thing the video shows us linking to right now is user32.lib, which I am linking against. Thanks again for all help.
Mārtiņš Možeiko
2565 posts / 2 projects
Day 002 - OutputDebugString: identifier not found
Your code doesn't use OutputDebugString function. It uses OutputDebugStr function. So error message with "OutputDebugString" identifier doesn't make any sense. Are you sure you are compiling correct file?

And actual function is called OutputDebugString. So you should be getting errors for OutputDebugStr function that you are trying to use.
Joshua T Bills
3 posts
Day 002 - OutputDebugString: identifier not found
Thank you very much!
Silly how many times I looked over that, just to (as usual) look over a mistyped variable name.
Mārtiņš Možeiko
2565 posts / 2 projects
Day 002 - OutputDebugString: identifier not found
No problem. That happens to everybody who writes code. Just read the error messages more carefully, they usually tell you exactly what is wrong and in what line that happens.

But it is not clear to me how can you get error for 'OutputDebugString' identifier if you don't use one...
Joshua T Bills
3 posts
Day 002 - OutputDebugString: identifier not found
Edited by Joshua T Bills on
Edit: Spelling

I really think my brain just lapsed that badly, that when I saw my code (ending in Str) and the video code (ending in String), my brain just could not straighten the signals, but merged them.

I get really uptight over compiler warnings and assume that I am correct, and the compiler is dumb. When in reality it is the computer that is dumb, and feeds the compiler exactly what I tell it to. Thus, since I am dumb, GetError() returns EGG_ON_FACE.