Search code examples
c++cross-platformentry-pointfltk

Cross Platform Entry Function That Doesn't Show Console


I'm using a cross platform GUI library (FLTK) to make some GUI with, I'm not using the Win32 API. I want this program to run on a Windows, Linux and Mac OS.

I don't really get how cross platform mumbo jumbo works (look at my account name), but I think understand what it means to be cross platform. But that's not my question.

My problem is that my entry function right now is simply int main(), but when I use this entry function, the console pops up. I don't want any consoles, so I know that I could make my entry function like this:

int wWinMain(HINSTANCE hInst, HINSTANCE hPreInst, LPWSTR nCmdLine, int nCmdShow)

and there would be no console.

My fear is that since I have to use the Win32 API to have this wWinMain entry function (because of the HINSTANCEs and the LPWSTR), the program would no longer be compatible with other OS's.

So my question is, will my program work on a Mac and Linux OS if I use the wWinMain function? If not, is there a function that I can use that creates no console and will work on all OS's?

Finally, perhaps I'm completely delusional about being able to have the same .exe program work on any OS, and that is in fact not possible. Is this so?


Solution

  • *NIX systems shouldn't spawn terminal windows by default, so you'll probably only have to do something special on Windows.

    If you can wrap the WinMain function, that is, put #define guards around it and call another function that acts as the "real" main inside of it, and then call that function from main on other platforms there should be no major issues.

    However, I'd strongly suggest avoiding wide characters (wchar_t) whereever possible because they differ from platform to platform and handling platform-specific API calls that need them by internally storing all strings as, for instance, UTF-8, converting them (For example via MultiByteToWideChar) only to make the API call.

    Basically, non-Windows platforms will need you to use a standard main function, Windows will need you to use WinMain. Make them both call a third function that handles what your main function should and return.

    Also, any Windows PE binary (.exe file) will only work on Windows. You'll have to compile your program for each platform separately regardless of what you do.