Jump to content
  • Advertisement
Sign in to follow this  
jeffreyp23

main and winMain

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

Good afternoon,

I got a question about using int main() and WINAPI WinMain together.
Is this possible? Because my idea was to wrap the WINAPI winMain in a class
and using int main() as the "main" entry point so you need to create an instance
of my class which handles all the window stuff. Like in Irrlicht. But after some google
searches i read that you can't wrap WinMain in a class. So that might be a problem.

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
You can't wrap WinMain in a class because it expects a certain function signature, and the this parameter would interfere with that (although it could probably be a static member function; I haven't tried anything like this). I am not entirely sure why you would want to do this, since both main() and WinMain define an entry point and it doesn't make much sense to have two entry points in a program.

Share this post


Link to post
Share on other sites
The reason i want to do this is because it will allow me to hide all the window related stuff in a class,
so the user doesn't have to deal with native windows function etc.

Share this post


Link to post
Share on other sites
This is the template code I use for all my applications. I do not see any win32 related stuff. You may think of using WinMain as the entry-point instead is something win32 related. OK. I see no further going way to encapsulate the windows related stuff.


CNativeClient *App=0;

extern "C" {

#ifdef __linux__

int main(int argc, char **argv, char **envp) {
App = new CNativeClient;
if (App != 0) {
if (App->InitInstance(argc,argv,envp)==true) {
return (App->Run());
} else {
return (-1);
}
} else {
return (-2);
}
}

#endif // __linux__

#ifdef _WIN32

int main(int argc, char *argv[]) {
int errorcode=0;
App = new CNativeClient;
if (App != 0) {
if (App->InitInstance(argc,argv, 0)==true) {
errorcode=App->Run();
App->ExitInstance();
delete App;
return (errorcode);
} else {
delete App;
return (-1);
}
} else {
return (-2);
}
}

#endif // _WIN32

};

Share this post


Link to post
Share on other sites

This is the template code I use for all my applications. I do not see any win32 related stuff. You may think of using WinMain as the entry-point instead is something win32 related. OK. I see no further going way to encapsulate the windows related stuff.


CNativeClient *App=0;

extern "C" {

#ifdef __linux__

int main(int argc, char **argv, char **envp) {
App = new CNativeClient;
if (App != 0) {
if (App->InitInstance(argc,argv,envp)==true) {
return (App->Run());
} else {
return (-1);
}
} else {
return (-2);
}
}

#endif // __linux__

#ifdef _WIN32

int main(int argc, char *argv[]) {
int errorcode=0;
App = new CNativeClient;
if (App != 0) {
if (App->InitInstance(argc,argv, 0)==true) {
errorcode=App->Run();
App->ExitInstance();
delete App;
return (errorcode);
} else {
delete App;
return (-1);
}
} else {
return (-2);
}
}

#endif // _WIN32

};




Yes something like this, but does this handle the WINAPI stuff inside the class?



Why do you want to wrap WinMain in a class? Is this an exercise in cross-platform compiling?


I'm just wondering how libraries like Irrlicht(a directX wrapper) handle this.
The only way i could think of to hide window related things is to wrap this into a class.
For example irrlicht runs in a standard int main and handles window/directx things into a class.

Share this post


Link to post
Share on other sites
You only need one entry point, whether that's main or WinMain. You don't need a WinMain to create windows, you can do that from main. Likewise you don't need main to create a console window, you can allocate one from WinMain.

Share this post


Link to post
Share on other sites

You only need one entry point, whether that's main or WinMain. You don't need a WinMain to create windows, you can do that from main. Likewise you don't need main to create a console window, you can allocate one from WinMain.

Can i create a directX window using int main()?
After some quick searches i only found how to allocate a console in a windows application,
but not how to allocate a window in a console application.

Share this post


Link to post
Share on other sites
Yes, you can create a window in a console subsystem application. It works exactly the same as creating a window in a window subsystem application.

Share this post


Link to post
Share on other sites

Yes, you can create a window in a console subsystem application. It works exactly the same as creating a window in a window subsystem application.


Oke thanks : )

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!