繁体   English   中英

VS2005中的基本Windows编程问题

[英]Basic Windows Programming question in VS2005

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

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

}

编译器错误。

错误C3861:“ MessageBoxPrintf”:找不到标识符

错误C2365:“ MessageBoxPrintf”:重新定义; 先前的定义是“以前未知的标识符

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

可以将函数MessageBoxPrintf放在WinMain函数之前,也可以在winMain之前添加原型。 通过输入以下行来添加原型:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM