Deleting intermediate files and output files for project 'Cpp1 - Win32 Release'.
--------------------Configuration: Cpp1 - Win32 Release--------------------
Compiling...
Cpp1.cpp
Linking...
LIBC.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Release/Cpp1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.Cpp1.exe - 2 error(s), 0 warning(s)代码:
#include<windows.h>
LONG WINAPI WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg; wc.style = 0;
wc.lpfnWndProc =(WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;    wc.hIcon = LoadCursor(NULL, IDI_WINLOGO
); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszMenuName = NULL;
wc.lpszClassName = "MyWndClass"; RegisterClass(&wc);
    hwnd = CreateWindow(
"MyWndClass",
"SDK Application",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP, NULL,
hInstance,
NULL
);
ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps; HDC hdc;
switch(message){
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
Ellipse(hdc, 0, 0, 200, 100);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;


}return DefWindowProc(hwnd, message, wParam, lParam);
}

解决方案 »

  1.   

    LIBC.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Release/Cpp1.exe : fatal error LNK1120: 1 unresolved externals
    ==========================================
    工程类型错了,应该选windows Application的,选了windows console appliction了,现在可以这样处理:工程的projects setting中的Link选项最下面有一个:Projects options:将其中的"/subsystem:windows "删除.
      

  2.   

    是将 /subsystem:console 删除
      

  3.   

    对,上面说的不错,你选的是console工程
      

  4.   

    ShowWindow(hwnd, nCmdShow);UpdateWindow(hwnd);
    我执行到这两句后怎么不见窗体出现呢?
      

  5.   

    少设了一个参数,加上下面一句
    wc.hCursor = NULL;
      

  6.   

    wc.style = 0;
    ======================
    没有设置窗口类的风格,一般设置成wc.sytle=CS_HREDRAW | CS_VREDRAW
    wc.hCursor没有设置,一般写成wc.hCursor=LoadCursor (NULL, IDC_ARROW);