Question

I was wondering, is it possible to use the entry point of a win32 program - the WinMain - as a class method? For example;

class cApp {
public:
    cApp();
   ~cApp();

    cGuiManager* guiManager;
   cServerManager* serverManager;
    cAudioManager* audioManager;

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hInst, LPSTR lpCmdLine, int nCmdShow);
    static LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
};

Thanks!

Was it helpful?

Solution

No. WinMain cannot be a member of class as "entry" point of the program. And for that matter, WinMain cannot be in any namespace (other than the global namespace). For example, even user::WinMain as shown below cannot be the "entry" point of the program.

namespace user
{
     int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int );
}

Entry point of the program must be defined in the global namespace.

However, you can have a function with this name inside a class (or in some other namespace), which you can call from the actual entry point WinMain defined in the global namespace. ButcApp::WinMain (or user::WinMain) is in no way the "entry" point of the program.

OTHER TIPS

Firstly it (and the WndProc) would need to to be static members to match the required prototypes. The real problem is getting the compiler to bind to a no global function, for that you need to use a linker option such as msvc's /entry:<symbol> to try bind to the static class member, however it might bug out on the scope resolution... If you can't have static members, you can use the CRT winmain entry to create then instance of your object and then call its WinMain member func, ofc you then might not be able to bind directly to the standard libraries and you'd need to do the CRT init yourself(though that can be grabbed from the crt msvc source)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top