Skip to main content
GameDev.net gamedev.net
🔒 Locked

Newbie Question with static pointer?

Started by Tarpedoe81 Jul 6, 2008 at 9:05 PM 1 replies 1k views
Original Post
Tarpedoe81
Tarpedoe81
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.
fpsgamer
fpsgamer
Did you remember to allocate an instance of cApplication? Something like this for example:


cApplication *g_pApplication = new cApplication;
thre3dee
thre3dee
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.