2011-09-02 57 views
0

我创建了一个win32控制台应用程序(没有启用预编译头选项)。 现在我的源代码是这样的,有两个编译器错误。VS2005中的基本Windows编程问题

// 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"), 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); 

} 

编译器错误。

error C3861: 'MessageBoxPrintf': identifier not found

error C2365: 'MessageBoxPrintf' : redefinition; previous definition was 'formerly unknown identifier

我该如何解决这些错误。感谢您的阅读和答复。

回答

1

要么将​​函数MessageBoxPrintf放在WinMain函数之前,要么在winMain之前添加原型。您可以通过输入以下命令行添加原型:

int CDECL MessageBoxPrintf(TCHAR * szCaption, TCHAR * szFormat, int x, int y); 
+0

其次您的建议,但仍显示链接错误:*错误LNK2019:在函数解析的外部符号_main引用___ tmainCRTStartup * –

+0

然后,我改变了'INT APIENTRY的WinMain(。 ..)'到'int _tmain(...)'。它现在有效。谢谢。 –