Jump to content
  • Advertisement
Sign in to follow this  
Endurion

Subclassing, Windows 98, Crash [SOLVED]

This topic is 4818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, i recently stumbled on a weird crash issue with my general framework. Usually i subclass my main window one or even more often. This always seemed to work nice and dandy on 2000/XP and i'm pretty sure i've done it before on 9x as well. Now i run into a crash on Windows 98 and i have no idea what causes it. The first message that runs through the subclasses proc runs gets processed but as soon as the subclass windowproc returns it crashes (in kernel32.dll). Alas i have no debugging utilities on 98 anymore, just a test machine is available. Could anyone with a studio running on 98 (VS6?) please take a look at that code (brutally stripped down but generates the crash). I can't see anything blatant wrong, but there's got to be something:
#include <windows.h>



HINSTANCE       m_hInstance = NULL;

char            szClassName[] = "Test98";

HWND            m_hwndMain = NULL;

WNDPROC         wndProcOld = NULL;



LRESULT XFrameAppWindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{

  switch ( message )
  {
    case WM_CLOSE:
      DestroyWindow( hWnd );
      return 0;
    case WM_DESTROY:
      PostQuitMessage( 0 );
      return 0;
  }

  return ::DefWindowProc( hWnd, message, wParam, lParam );

}



LRESULT WINAPI SubclassWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{

  // simply call the original window proc
  return CallWindowProc( wndProcOld, hWnd, uMsg, wParam, lParam );

}


 

bool Create( DWORD dwStyle, int iWidth, int iHeight, const char* szCaption )
{

  WNDCLASS    WndClass;

  ZeroMemory( &WndClass, sizeof( WndClass ) );
  WndClass.style          = CS_HREDRAW | CS_VREDRAW;
  WndClass.lpfnWndProc    = (WNDPROC)XFrameAppWindowProc;
  WndClass.hInstance      = m_hInstance;
  WndClass.hIcon          = NULL;
  WndClass.hCursor        = NULL;
  WndClass.hbrBackground  = NULL;
  WndClass.lpszMenuName   = NULL;
  WndClass.lpszClassName  = szClassName;
  if ( !RegisterClass( &WndClass ) )
  {
    return false;
  }

  m_hwndMain = CreateWindow( szClassName, 
                             szCaption, dwStyle, 
                             0, 0, 
                             iWidth, iHeight,
                             NULL,
                             0,
                             m_hInstance,
                             0 );
  if ( m_hwndMain )
  {
    // now subclass the windowproc (works fine on 2000/XP)
    wndProcOld = (WNDPROC)SetWindowLong( m_hwndMain, GWL_WNDPROC, (LONG)SubclassWindowProc );
  }

  return ( !!m_hwndMain );

}





int WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR lpCmdLine, int iCmdShow )
{

  m_hInstance = hInst;

  Create( WS_VISIBLE | WS_OVERLAPPEDWINDOW, 640, 480, "Hurz" );

  while ( IsWindow( m_hwndMain ) )
  {
    MSG   msg;

    while ( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
    {
      BOOL    bRet = GetMessage( &msg, NULL, 0, 0 );

      if ( bRet == 0 )
      {
        break;
      }
      else if ( bRet == -1 )
      {
        // Error!
        break;
      }
      else
      {
	      ::TranslateMessage( &msg );
	      ::DispatchMessage( &msg );
      }
    }
  }

  return 0;

}



Just create an empty Win32 project and paste the whole block inside. Should compile. Ignore the W64 warnings (i know SetWindowLongPtr, i just wanted to make sure it works fine on 98) on VS 2002/2003. All the code does is to create a window, subclass it and run a message loop. The subclass proc simply calls the original window proc without further processing. Thanks in advance to anyone who can give me a hint! [Edited by - Endurion on September 13, 2005 2:41:07 AM]

Share this post


Link to post
Share on other sites
Advertisement
LRESULT XFrameAppWindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )

should be

LRESULT CALLBACK XFrameAppWindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )

Share this post


Link to post
Share on other sites
Colin Jeanne: SetWindowLong works, i put in logging and the first message to the window actually does run through the new subclass proc

spock: Holy spacerat-on-a-stick batman, that was it! And i was frigging sure i had that in. I checked several times on the main windowproc but not on the subclass proc. Thanks a bunch! It works now like a charm!

Ratings++ for both of you!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!