int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
TCHAR szBuffer [1024] ;
va_list pArgList ;
// The va_start macro (defined in STDARG.H) is usually equivalent to:
// pArgList = (char *) &szFormat + sizeof (szFormat) ;
va_start (pArgList, szFormat) ;
// The last argument to wvsprintf points to the arguments
_vsntprintf (szBuffer, sizeof (szBuffer) / sizeof (TCHAR),
szFormat, pArgList) ;
// The va_end macro just zeroes out pArgList for no good reason
va_end (pArgList) ;
return MessageBox (NULL, szBuffer, szCaption, 0) ;
}
int WINAPI WinMain (
__in HINSTANCE hInstance,
__in_opt HINSTANCE hPrevInstance,
__in_opt LPSTR lpCmdLine,
__in int nShowCmd
){
int cxScreen = 800, cyScreen = 600;
MessageBoxPrintf (TEXT ("ScrnSize"),
TEXT ("The screen is %i pixels wide by %i pixels high."),
cxScreen, cyScreen) ;
}
int __cdecl _vsprintf_l (
char *string,
const char *format,
_locale_t plocinfo,
va_list ap
)
{
FILE str;
REG1 FILE *outfile = &str;
REG2 int retval;
_VALIDATE_RETURN( (format != NULL), EINVAL, -1);
#ifdef _COUNT_
_VALIDATE_RETURN( (count == 0) || (string != NULL), EINVAL, -1 );
#else /* _COUNT_ */
_VALIDATE_RETURN( (string != NULL), EINVAL, -1 );
#endif /* _COUNT_ */
#ifndef _COUNT_
outfile->_cnt = MAXSTR;
#else /* _COUNT_ */
if(count>INT_MAX)
{
/* old-style functions allow any large value to mean unbounded */
outfile->_cnt = INT_MAX;
}
else
{
outfile->_cnt = (int)count;
}
#endif /* _COUNT_ */
outfile->_flag = _IOWRT|_IOSTRG;
outfile->_ptr = outfile->_base = string;
#ifndef _SWPRINTFS_ERROR_RETURN_FIX
retval = _output_l(outfile, format, plocinfo, ap );
#else /* _SWPRINTFS_ERROR_RETURN_FIX */
retval = outfn(outfile, format, plocinfo, ap );
#endif /* _SWPRINTFS_ERROR_RETURN_FIX */
if ( string==NULL)
return(retval);
#ifndef _SWPRINTFS_ERROR_RETURN_FIX
_putc_nolock('/0',outfile);
return(retval);
#else /* _SWPRINTFS_ERROR_RETURN_FIX */
if((retval >= 0) && (_putc_nolock('/0',outfile) != EOF))
return(retval);
string[count - 1] = 0;
if (outfile->_cnt < 0)
{
/* the buffer was too small; we return -2 to indicate truncation */
return -2;
}
return -1;
#endif /* _SWPRINTFS_ERROR_RETURN_FIX */
}
int __cdecl _output_l (
FILE *stream,
const _TCHAR *format,
_locale_t plocinfo,
va_list argptr
)
{
.....
......
/* main loop -- loop while format character exist and no I/O errors */
while ((ch = *format++) != _T('/0') && charsout >= 0) {
chclass = FIND_CHAR_CLASS(__lookuptable, ch); /* find character class */
state = FIND_NEXT_STATE(__lookuptable, chclass, state); /* find next state */
_VALIDATE_RETURN((state != ST_INVALID), EINVAL, -1);
switch (state) {
case ST_NORMAL:
if (_isleadbyte_l((unsigned char)ch, _loc_update.GetLocaleT())) {
WRITE_CHAR(ch, &charsout);
ch = *format++;
/* don't fall off format string */
_VALIDATE_RETURN( (ch != _T('/0')), EINVAL, -1);
}
WRITE_CHAR(ch, &charsout);
break;
......
......
}
......
......
}
#define WRITE_CHAR(ch, pnw) write_char(ch, stream, pnw)
LOCAL(void) write_char (
_TCHAR ch,
FILE *f,
int *pnumwritten
)
{
if ( (f->_flag & _IOSTRG) && f->_base == NULL)
{
++(*pnumwritten);
return;
}
#ifdef _UNICODE
if (_putwc_nolock(ch, f) == WEOF)
#else /* _UNICODE */
if (_putc_nolock(ch, f) == EOF)
#endif /* _UNICODE */
*pnumwritten = -1;
else
++(*pnumwritten);
}
#define _putc_nolock(_c, _stream) _fputc_nolock(_c, _stream)
#define _fputc_nolock(_c,_stream) (--(_stream)._cnt >= 0 ? 0xff & (*(_stream)._ptr++ = (char)(_c)) : _flsbuf((_c),(_stream)))
//deal with arguments
switch (state) {
case ST_NORMAL:
switch (ch) {
case _T('i'):
l = get_int_arg(&argptr); /* sign extend */
__inline int __cdecl get_int_arg (
va_list *pargptr
)
{
return va_arg(*pargptr, int);
}
}
#define va_arg _crt_va_arg
#define _crt_va_arg(ap,t) ( *(t *)( (ap += _INTSIZEOF(t)) - _INTSIZEOF(t) )