为什么链接时老是出错?
KingI 2006-01-24 12:00:59 当我打开一个win32程序文件编译时没错,可是链接时就会出现下面的错误,
但我新建一个win32程序后,把代码复制到里面再编译链接, 就没错了,这是咋回事呢?
--------------------Configuration: win - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/win.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
win.exe - 2 error(s), 0 warning(s)
------------------------------------------------------------------------
这是源码:
#include <windows.h>
LRESULT CALLBACK Win(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iShowCmd)
{
WNDCLASS wndclass;
static TCHAR NAME[]="Windows";
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL, IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL, IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=Win;
wndclass.lpszClassName=NAME;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW | CS_VREDRAW;
if(!RegisterClass(&wndclass)) {
MessageBox(NULL, TEXT("Must run in Windows NT!"), TEXT("Error"), MB_OK);
return 0;
}
HWND hWnd1=CreateWindow(NAME,
TEXT("Hello Windows1"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd1, iShowCmd);
UpdateWindow(hWnd1);
MSG msg;
while (GetMessage(&msg, NULL, 0 ,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK Win(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch(iMsg) {
case WM_PAINT :
hdc=BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rect);
DrawText(hdc, TEXT("Hello Boy!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY :
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}