simple ucrtbase printf test.
many of us have now that dll in their system.
ucrtbase.dll don't have printf, fprintf, ...
#include <stdarg.h>
// https://msdn.microsoft.com/en-us/library/dn727675.aspx
// https://blogs.msdn.microsoft.com/vcblog/2014/06/18/c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1/
void exit(int status);
typedef struct FILE FILE;
#undef stdin
#undef stdout
#undef stderr
//__declspec(dllimport)
extern FILE* __cdecl __acrt_iob_func(unsigned);
#define stdin (__acrt_iob_func(0))
#define stdout (__acrt_iob_func(1))
#define stderr (__acrt_iob_func(2))
#pragma comment (lib, "ucrtbase.lib")
int __cdecl __stdio_common_vfprintf(long long, FILE*, char const* , int, va_list);
int printf(const char * format, ...)
{
int ret;
va_list vl;
va_start(vl, format);
ret = __stdio_common_vfprintf(0, stdout, format, 0, vl);
va_end(vl);
return ret;
}
int fprintf(FILE * stream, const char * format, ...)
{
int ret;
va_list vl;
va_start(vl, format);
ret = __stdio_common_vfprintf(0, stream, format, 0, vl);
va_end(vl);
return ret;
}
int main(int argc, char **argv);
void __cdecl mainCRTStartup(void)
{
exit(main(0, 0));
}
int main(int argc, char **argv)
{
printf("Hello C\n");
fprintf(stdout, "StdOut\n");
fprintf(stderr, "StdErr\n");
return 0;
}
argc argv don't work yet
extern FILE* __cdecl __acrt_iob_func(unsigned);
FILE* stdin;
FILE* stdout;
FILE* stderr;
int main(int argc, char **argv);
void __cdecl mainCRTStartup(void)
{
stdin = __acrt_iob_func(0);
stdout = __acrt_iob_func(1);
stderr = __acrt_iob_func(2);
exit(main(0, 0));
}
speed test with qsort:
msvcrt.dll 250ms
ucrtbase.dll 285ms
PS: last Firefox have those dll's, if someone don't have those, just copy from there.
These are needed in Windows 7
2 048 test_ucrt.exe
921 280 ucrtbase.dll
18 624 api-ms-win-core-file-l1-2-0.dll
18 624 api-ms-win-core-file-l2-1-0.dll
21 184 api-ms-win-core-localization-l1-2-0.dll
19 136 api-ms-win-core-processthreads-l1-1-1.dll
19 136 api-ms-win-core-synch-l1-2-0.dll
18 624 api-ms-win-core-timezone-l1-1-0.dll
WindowsXP:
ucrtbase.dll
api-ms-win-core-console-l1-1-0.dll
api-ms-win-core-datetime-l1-1-0.dll
api-ms-win-core-debug-l1-1-0.dll
api-ms-win-core-errorhandling-l1-1-0.dll
api-ms-win-core-file-l1-1-0.dll
api-ms-win-core-file-l1-2-0.dll
api-ms-win-core-file-l2-1-0.dll
api-ms-win-core-handle-l1-1-0.dll
api-ms-win-core-heap-l1-1-0.dll
api-ms-win-core-interlocked-l1-1-0.dll
api-ms-win-core-libraryloader-l1-1-0.dll
api-ms-win-core-localization-l1-2-0.dll
api-ms-win-core-memory-l1-1-0.dll
api-ms-win-core-namedpipe-l1-1-0.dll
api-ms-win-core-processenvironment-l1-1-0.dll
api-ms-win-core-processthreads-l1-1-0.dll
api-ms-win-core-processthreads-l1-1-1.dll
api-ms-win-core-profile-l1-1-0.dll
api-ms-win-core-rtlsupport-l1-1-0.dll
api-ms-win-core-string-l1-1-0.dll
api-ms-win-core-synch-l1-1-0.dll
api-ms-win-core-synch-l1-2-0.dll
api-ms-win-core-sysinfo-l1-1-0.dll
api-ms-win-core-timezone-l1-1-0.dll
api-ms-win-core-util-l1-1-0.dll
EDIT: startup code for ucrtbase.dll
extern int* __cdecl __p___argc (void);
extern char*** __cdecl __p___argv (void);
extern char*** __cdecl __p__environ (void);
//extern wchar_t*** __cdecl __p___wargv(void);
extern int _configure_narrow_argv(int);
int main(int argc, char **argv);
void __cdecl mainCRTStartup(void)
{
_configure_narrow_argv(1);
int __argc = *__p___argc();
char** __argv = *__p___argv();
//char**__env = *__p__environ();
exit(main(__argc, __argv));
}