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


  • Member
  • ****
  • Posts: 551
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
#define GETARGS __getmainargs
#define GETARGS __GetMainArgs
(long*,char***,char***, long, long*);

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



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:


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

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

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