1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
//=====================================================================================
// Developed As An Addition To Matt Pietrek's LibCTiny.lib
// By Fred Harris, January 2016
//
// cl printf.cpp /GS- /c /W3 /DWIN32_LEAN_AND_MEAN
//=====================================================================================
#include <windows.h>
#include <stdarg.h>
extern "C" int __cdecl printf(const char* format, ...);
extern "C" int __cdecl wprintf(const wchar_t* format, ...);
#pragma comment(linker, "/defaultlib:user32.lib") // Force the linker to include USER32.LIB
extern "C" int __cdecl printf(const char* format, ...)
{
char szBuff[1024];
DWORD cbWritten;
va_list argptr;
int retValue;
va_start(argptr, format);
retValue = wvsprintf(szBuff, format, argptr);
va_end(argptr);
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), szBuff, retValue, &cbWritten, 0);
return retValue;
}
extern "C" int __cdecl wprintf(const wchar_t* format, ...)
{
wchar_t szBuffW[1024];
char szBuffA[1024];
int iChars,iBytes;
DWORD cbWritten;
va_list argptr;
va_start(argptr, format);
iChars = wvsprintfW(szBuffW, format, argptr);
va_end(argptr);
iBytes=WideCharToMultiByte(CP_ACP,0,szBuffW,iChars,szBuffA,1024,NULL,NULL);
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), szBuffA, iBytes, &cbWritten, 0);
return iChars;
}
|