   Wrapping WinMain into a class ?
  Hi all,What I have is a singleton class (pattern) which initializes directx, does enumeration checks etc and contains the main message game loop. The game loop has a pointer to function as one of the parameters to call back to my main window code.  My main window code contains the WinMain function and WndProc as well as the call back function just mentioned.  Within this main window code I have global pointers to various other classes I have created, I was wondering if it is possible to make the main window code into a class and thus remove the annoyance of having global objects ?  I suppose a little like how MFC wraps up the main windows message loop etc.  Thus what I want is a class which holds the WinMain and WndProc functions.Does this make sense ?Regards,Steve   
Quote:Original post by garadeDoes this make sense ?Not quite.WndProc is invoked on specific window objects, so it makes sense to look at a method of encapsulating it as a method object. There are several published methods for accomplishing this, including my (severely dated) article on the subject: Creating a Win32 Window Wrapper Class.WinMain, on the other hand, is your application entry point. While it is possible to turn it into a static class method and reroute your application initiation there, it doesn't profit as you will still need to instantiate initial objects and resolve scoping issues. It's probably more effective to investigate namespaces for managing your global object name collisions.Also, be careful about overuse of the singleton pattern. It's not quite the silver bullet you might imagine it to be, and it may come back to bite you in unpleasant places.;  Very strange, just found your article and have been reading it just before you posted !Think I will use namespaces.Many thanks for your input.Steve;  If you look at the samples that come with the DX SDK, MS has a pretty good example of how to wrap it up in a class.  It's probably very similar to the article posted above.   ;  I recommend looking at NeHe's OOP basecode. It is OpenGL based, but you can extract the concept out and apply it to your DX based game. I have used his concept and it works beautifully. The basic premise:You pass a pointer to your application instance as the last parameter in CreateWindow(). In the WndProc function, on the WM_CREATE message, you get the pointer out of the CREATESTRUCT and set is as the window long using SetWindowLong. On any other message besides WM_CREATE, you retrieve the pointer to the application using GetWindowLong and cast it back to a pointer and then call the WndProc that it defines. Sorry if the details are a little off. I am writing this from what I remember from more than a few months ago.NeHeLatest NeHe OOP Basecode