_vsnprintf()的一个问题

来源:互联网 发布:js 清除 cookie的方法 编辑:程序博客网 时间:2024/06/13 08:22

最近在看《Windows程序设计(第五版)》 程序2-1 写下来不能运行

#include<Windows.h>#include<tchar.h>#include<stdio.h>int CDECL MessageBoxPrintf(TCHAR *szCaption,TCHAR *szFormat,...){TCHAR szBuffer[1024];va_list pArgList;va_start(pArgList,szFormat);_vsnprintf(szBuffer,sizeof(szBuffer)/sizeof(TCHAR),szFormat,pArgList);va_end(pArgList);return MessageBox(NULL,szBuffer,szCaption,0);}int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iShowCmd){int cxScreen,cyScreen;cxScreen = GetSystemMetrics (SM_CXSCREEN);cyScreen = GetSystemMetrics (SM_CYSCREEN);MessageBoxPrintf(TEXT("Scrnsize"),TEXT("The Screen is i% pixels wide by i% pixels high"),cxScreen,cyScreen);return 0;}

说_vsnprintf()的第一个参数TCHAR *和char *不兼容,不过书上说TCHAR 在有Unicode的时候会变成w_char,否则就是char

TCHAR *难道和 char *不是一个道理吗?大哭 想不通


----------------------------------------------------------------------------------------华丽的分割线-----------------------------------------------------------------------------------------------------------------------------

原来是我傻X了,_vsnprintf()和_vsntprintf()是两个函数,一个是处理char的 一个是处理TCHAR的。大家注意就好~~

可是貌似并没有格式化我的输出,不知道是不是我又傻了

输出是:

The screen is i00000566ixels wide by i00000300ixels high

原创粉丝点击