Newsgroup: it.comp.programmare.win32
Titolo: errore con mingw e programmino win32

Ciao,
sto cercando di compilare un programmino trovato in un tutorial per directx,
il quale dovrebbe semplicemente aprire una finestra.
Il problema è che riesco a compilare, ma il linking mi dà un errore:
"undefined reference to getStockObject@4". In fondo allego il codice che ho
utilizzato.
Qualcuno sa come risolvere il problema?
Più in generale, ha senso usare mingw32 e gcc3.2 per sviluppare con directx
o devo prostituirmi a zio Bill?
Grazie
Ciao
Alex.
//--------------------------------------------------------------------------
---
  // Filename: Win32Creation.cpp
  // Description: Creates a simple Win32 window on screen
//--------------------------------------------------------------------------
---
  #define WIN32_LEAN_AND_MEAN
  #include <windows.h>
  // Function declarations
  int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow);
  LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM
lParam );
  static char strAppname[]="Our First Win32 App!";
//--------------------------------------------------------------------------
---
  // Name: WinMain()
  // Desc: The application's entry point
//--------------------------------------------------------------------------
---
  int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
  {
      WNDCLASSEX wc;
      ZeroMemory(&wc, sizeof(WNDCLASSEX));
      wc.cbSize=sizeof(WNDCLASSEX);                       // size of the
window struct in bytes
      wc.style=CS_HREDRAW | CS_VREDRAW | CS_OWNDC;        // window styles
to use
      wc.lpfnWndProc=MsgProc;                             // function name
of event handler
      wc.hInstance=hInstance;                             // handle to this
apps instance
      wc.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);// background
colour of window
      wc.hIcon= LoadIcon(NULL, IDI_APPLICATION);          // icon for the
app window
      wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION);         // icon when
minimized to taskbar
      wc.hCursor=LoadCursor(NULL, IDC_ARROW);             // cursor to use
for this window
      wc.lpszClassName=strAppname;                        // name for this
class
      // Register the window class
      RegisterClassEx( &wc );
      // Create the application's window
      HWND hWnd = CreateWindow(strAppname, strAppname,
          WS_OVERLAPPEDWINDOW, 100, 100, 640, 480,
          NULL, NULL, hInstance, NULL );
      // Show the window
      ShowWindow( hWnd, nCmdShow );
      UpdateWindow( hWnd );
      // Enter the message loop
      MSG msg;
      ZeroMemory( &msg, sizeof(msg) );
      while( msg.message!=WM_QUIT )
      {
          if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
          {
              TranslateMessage( &msg );
              DispatchMessage( &msg );
          }
          else
          {
              // no winmessages, idle code here
          }
      }
      UnregisterClass( strAppname, hInstance );
      return 0;
  }
//--------------------------------------------------------------------------
---
  // Name: MsgProc()
  // Desc: The window's message handler
//--------------------------------------------------------------------------
---
  LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM
lParam )
  {
      HDC hDC;
      PAINTSTRUCT PaintStruct;      switch( msg )
      {
      case WM_PAINT:
          {
              hDC=BeginPaint(hWnd, &PaintStruct);     // Tell windows we
want to update the window
              // Do GDI drawing here
              EndPaint(hWnd, &PaintStruct);
              return 0;
          }
      case WM_DESTROY:
          {
              PostQuitMessage( 0 );
              return 0;
          }
      default:
          return DefWindowProc( hWnd, msg, wParam, lParam );
      }
  }

Qualcuno sa come risolvere il problema?
libgdi32.a
sbirish.


trovata, cosa devo farne adesso? la passo come parametro della linea di
comando per il linker?
grz.
ciao

comando per il linker?
si..
Alt+p -> parameters -> Add library or Object se usi il devcpp
 -l altrimenti
GCC(1)            GNU Tools                     GCC(1)
[...]
-llibrary
 Use the library named library when linking.
 The  linker  searches a standard list of directories for the li-
 brary, which is actually a file named `liblibrary.a'.  The link-
 er  then uses this file as if it had been specified precisely by
 name.
 The directories searched include several standard system  direc-
 tories plus any that you specify with `-L'.
 Normally  the  files  found  this way are library files--archive
 files whose members are object files.   The  linker  handles  an
 archive  file  by  scanning  through it for members which define
 symbols that have so far been referenced but not defined.   How-
 ever,  if the linker finds an ordinary object file rather than a
 library, the object file is linked in the  usual  fashion.   The
 only  difference  between  using an `-l' option and specifying a
 file name is that `-l' surrounds library with `lib' and `.a' and
 searches several directories.
sbirish.

  Use the library named library when linking.
Ti ringrazio tantissimo per la dritta.
Ho aggiunto -lgdi32 alla linea di comando e ora funzia tutto.
Però tanto per capire, quel getstockobject è una funzione definita in gdi32?
Ciao
Alex.

 o devo prostituirmi a zio Bill?
Questa domanda invece è sempre valida, accetto ogni genere di consiglio.

Però tanto per capire, quel getstockobject è una funzione definita in gdi32?
già
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_1t10.asp
Requirements 
  Windows NT/2000/XP: Included in Windows NT 3.1 and later.
  Windows 95/98/Me: Included in Windows 95 and later.
  Header: Declared in Wingdi.h; include Windows.h.
  Library: Use Gdi32.lib.
sbirish.