#include <windows.h>
#include <tchar.h>     
#include <stdio.h>     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 ( 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 ;
}
这么段小程序这什么通不过呢,我编译能通过的但构件就不行了
-------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Cpp1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.Cpp1.exe - 2 error(s), 0 warning(s)整出个这个错误怎么解决呢。????

解决方案 »

  1.   

    你的工程是不是unicode呀?把int WINAPI WinMain 改成_tWinMain试试
      

  2.   

    /*-----------------------------------------------------
       SCRNSIZE.C -- Displays screen size in a message box
                     (c) Charles Petzold, 1998
      -----------------------------------------------------*/#include <windows.h>
    #include <tchar.h>     
    #include <stdio.h>     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 (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 ;
    }
      

  3.   

    可以啊,这个例子是Windows program design 第二章的例子
    我这里可以运行,没有问题。
      

  4.   

    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main这是告诉你找不到main函数你建的是console工程,console工程的入口函数应该是main,而不是winmain
    int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance,
    PSTR szCmdLine, int iCmdShow) 
    改成
    int main(int argc, char* argv[])或者把console改成win32 application
      

  5.   

    http://community.csdn.net/Expert/topic/4035/4035191.xml?temp=.755932