Author Topic: CRT startup code replacement for console programs, using MSVCRT and CRTDLL DLLs  (Read 2200 times)

Antariy

  • Member
  • ****
  • Posts: 541
The following code is the simple replacement for the startup code for console programs, that may be used with MSVC and any other compilers, and allowing to use MSVCRT.DLL or CRTDLL.DLL as a CRT library.

Code: [Select]
extern __declspec(dllimport) int __cdecl
#ifdef USE_MSVCRTDLL
__getmainargs
#define GETARGS __getmainargs
#else
__GetMainArgs
#define GETARGS __GetMainArgs
#endif
(long*,char***,char***, long, long*);

void _mainCRTStartup(){
long argc;
char** argv;
char** env;
long l;

GETARGS(&argc,&argv,&env,0,&l);

exit(main(argc,argv/*,env*/));
}

If the MSVCRT dll is required, then specify the USE_MSVCRTDLL macro, otherwise the CRTDLL will be used.
If the environment is required then uncomment env parameter passed to a main().
When linking use appropriate import library to the version which specified in the C code using a macro.
If the linker is not Microsoft's one then you should find manually how to exclude the standard libraries from the build and how to set up the entry point manually. For the Microsoft's one that are the commands: /NODEFAULTLIB and /ENTRY appropriately.

Some additional info about CRTDLL import library: http://masm32.com/board/index.php?topic=1418.msg32855#msg32855

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Alex,

very interesting idea.  :t I've to check the gcc linker options. Thank you.

Gunther
Get your facts first, and then you can distort them.