title: Undefined reference to __imp_Rectangle in C++
body: <p>I have been having trouble compiling some code in C++.</p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  
  LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
  
  int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int nShowCmd )
  {
  
      static char name[] = "My Application";
      WNDCLASSEX wc;
      HWND hwnd;
      MSG Msg;
  
      // Step 1: Registering the Window Class
      wc.cbSize = sizeof( WNDCLASSEX );
      wc.style = CS_HREDRAW | CS_VREDRAW;
      wc.lpfnWndProc = WndProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
      wc.hCursor = LoadCursor( NULL, IDC_ARROW );
      wc.hbrBackground = ( HBRUSH ) ( COLOR_WINDOW + 1 );
      wc.lpszMenuName = NULL;
      wc.lpszClassName = name;
      wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
  
      if ( !RegisterClassEx( &amp; wc ) )
      {
  
          MessageBox( NULL, "Window Registration Failed!", "Registration Failure", MB_ICONEXCLAMATION | MB_OK );
  
          return 0;
  
      }
  
      // Step 2: Creating the Window
      hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, name, "My First Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, NULL, NULL, hInstance, NULL );
  
      ShowWindow( hwnd, nShowCmd );
      UpdateWindow( hwnd );
  
      // Step 3: The Message Loop
      while( GetMessage( &amp; Msg, NULL, 0, 0 ) &gt; 0 )
      {
  
          TranslateMessage( &amp; Msg );
  
          DispatchMessage( &amp; Msg );
  
      }
  
      return ( int )Msg.wParam;
  
  }
  
  LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
  {
  
      HDC hdc;
      PAINTSTRUCT ps;
      RECT rect;
  
      switch( msg )
      {
  
          case WM_PAINT:
  
              hdc = BeginPaint( hwnd, &amp; ps );
  
              GetClientRect( hwnd, &amp; rect );
  
              Rectangle( hdc, rect.right / 2 - 50, rect.bottom / 2 - 20, rect.right / 2 + 50, rect.bottom / 2 + 20 );
  
              DrawText( hdc, "Hello World!", -1, &amp; rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
  
              EndPaint( hwnd, &amp; ps );
  
              break;
  
          case WM_CLOSE:
  
              DestroyWindow( hwnd );
  
              break;
  
          case WM_DESTROY:
  
              PostQuitMessage( 0 );
  
              break;
  
      }
  
      return DefWindowProc( hwnd, msg, wParam, lParam );
  
  }
  </code></pre>
  
  <p>The tutorial I am following says that it compiles correctly with no problems, but this is what my compiler looks like:</p>
  
  <pre><code>NPP_EXEC: "Compile C++ File"
  NPP_SAVE: G:\C++\src\Win32\Hello World! Window.cpp
  g++ -o "G:\C++\src\Win32\Hello World! Window" "G:\C++\src\Win32\Hello World! Window.cpp" -static
  Process started &gt;&gt;&gt;
  C:\Users\Braeden\AppData\Local\Temp\cc3N4Ls1.o:Hello World! Window.cpp:(.text+0x29b): undefined reference to `__imp_Rectangle'
  collect2.exe: error: ld returned 1 exit status
  &lt;&lt;&lt; Process finished.
  ================ READY ================
  </code></pre>
  
  <p>I am not using any popular IDE. I am using Notepad++ as a text editor and a MinGW distro as my compiler. I am on Win7 x64. Could someone tell me what I am doing wrong?</p>