Jump to content
  • Advertisement
Sign in to follow this  
Tarpedoe81

Newbie Question with static pointer?

This topic is 3753 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

I'm using Visual C++ 2008 Express Edition, and using the book, "Programming Role-Playing Games with DirectX, by Jim Adams." And I'm having a problem with this static pointer. Here is the static pointer being initialized: /* static cApplication *g_pApplication = NULL; */ cApplication is the class that handles most of the Windows code. The class also has a default message procedure. g_pApplication is the class pointer. What I'm trying to do is overload the message procedure. Here is the overloaded message procedure code: /* static long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; default: return g_pApplication->MsgProc(hWnd, uMsg, wParam, lParam); } } */ Here is the code for the default message procedure code: /* virtual long FAR PASCAL MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return DefWindowProc(hWnd, uMsg, wParam, lParam); } */ When the code compiles, in the Output window, it shows this error: /* First-chance exception at 0x7c918fea in Game Files.exe: 0xC0000005: Access violation writing location 0x00000010. */ It still compiles, but I want to know why it prints out the exception. Also, I want to know if it's a good idea to use the static pointer or just have the static message procedure. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Did you remember to allocate an instance of cApplication? Something like this for example:


cApplication *g_pApplication = new cApplication;

Share this post


Link to post
Share on other sites
Instead of using FAR PASCAL macros, use CALLBACK.

FAR doesn't have much use anymore. I believe its got something to do with 16-bit operating systems. Also, CALLBACK does the same thing that PASCAL does however the MSDN documentation specifies LRESULT CALLBACK WndProc (...) not FAR PASCAL.

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!