Basic Windows Programming question in VS2005
I created a win32 console application (without enable precompiled header option). And now my source code as this, there is two compiler errors.
// AFormattingMsgBox.cpp : Defines the entry point for the console application.
//
#include <windows.h>
#include "stdafx.h"
//int _tmain(int argc, _TCHAR* argv[])
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
int cxScreen, cyScreen;
cxScreen = GetSystemMetrics(SM_CXSCREEN);
cyScreen = GetSystemMetrics(SM_CYSCREEN);
MessageBoxPrintf(TEXT("ScrnSize&quo开发者_StackOverflow社区t;), TEXT("The screen is %i pixels wide by %i pixels high."), cxScreen, cyScreen);
return 0;
}
int CDECL MessageBoxPrintf(TCHAR * szCaption, TCHAR * szFormat, int x, int y)
{
TCHAR szBuffer [1024];
va_list pArgList;
va_start(pArgList, szFormat);
_vsntprintf(szBuffer, sizeof(szBuffer) / sizeof(TCHAR),
szFormat, pArgList);
va_end(pArgList);
return MessageBox(NULL, szBuffer, szCaption, 0);
}
Compiler Errors.
error C3861: 'MessageBoxPrintf': identifier not found
error C2365: 'MessageBoxPrintf' : redefinition; previous definition was 'formerly unknown identifier
How can I fix the errors. Thanks for your reading and replies.
Either put the function MessageBoxPrintf before the WinMain function or add a prototype before winMain. You add a prototype by entering the following line:
int CDECL MessageBoxPrintf(TCHAR * szCaption, TCHAR * szFormat, int x, int y);
精彩评论