C ++: execute custom main function

WinMain is a function that "replaces" the default main entry point with "main".

Then the user can determine his main entry point, for example

int WINAPI WinMain(...) { }


How is this done in the form of encapsulation?

Well, most likely, at some point it looks like this:

int main() // This must be defined somewhere in windows.h
{
    return WinMain(...);
}

Question . How can I perform such an encapsulation of my own, which then calls WinMain? Note. The library I created is a DLL, so it will look like this:

// This is the minimal code for the application which uses 'MyLibrary'
#pragma comment(lib, "MyLibrary.lib")
include "MyLibrary.h"

void Main(MyCustomParameter *params)
{
    // Write user code here
}

The problem is that the DLL does not "know" the function Main()and therefore generates a "unresolved external character" compilation error. So how can I encapsulate it as follows?

+5
source share
3

"extern" (extern "C" ++). , _main. :

extern "C" int my_main(int argc, char *argv[]);

int main(int argc, char *argv[])
{
    return my_main(argc, argv);
}
+3
+2

, , WinMain. - wWinMainCRTStartup, WinMainCRTStartup, wmainCRTStartup mainCRTStartup. Windows.h, CRT. <VS installation folder>\VC\crt\src\crtexe.c. , wWinMain, WinMain, wmain main .

- , /ENTRY, , .

+2

All Articles