Passing WinMain parameters to another function
-
28-02-2021 - |
Question
I'm developing an application on Windows, but I'd also like to support other platforms (the majority of code I've written is platform independent). Anyway, I figured for developments sake I'd like to keep things simple (perhaps I was naive in this approach) so my main.cpp
looks a little like the following:
#ifdef _WIN32
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR cmdLine,
int cmdShow)
#else
int main(int argc, char* argv[])
#endif
{
/* If the application is launched under Windows */
#ifdef _WIN32
win_init wi;
return wi.init(hInstance, hPrevInstance, cmdLine, cmdShow);
#endif
/* If the application is launched under OS X */
#ifdef __APPLE__
osx_init oi;
return oi.init();
#endif
}
So the idea is that if the application is launching under Windows, WinMain
is called and then I call wi.init with the WinMain arguments provided to do the rest.
I thought I was being smart, but when I compile I get an error:
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
I've researched this error and it seems to happen when people either forget a main method or try to compile a DLL as an .exe
So for my question; I am curious as to why this is happening, and what do you recommend I do instead of this approach?
Solution
You want to use the /SUBSYSTEM:WINDOWS
linker option in order for WinMain
to be used.