一个windows应用
程序代码:
#include<windows.h> #include<stdio.h> HINSTANCE hInst; HWND hWndMain; LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,PSTR lpszCmdLine,int nCmdShow) {MSG msg; WNDCLASS wnd; wnd.style=CS_HREDRAW |CS_VREDRAW; wnd.cbClsExtra = 0; wnd.cbWndExtra = 0; wnd.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH); wnd.hCursor = ::LoadCursor(NULL,IDC_ARROW); wnd.hIcon = ::LoadIcon(NULL,IDI_APPLICATION); wnd.hInstance = hInstance; wnd.lpfnWndProc = WndProc; wnd.lpszClassName="generic"; wnd.lpszMenuName = NULL; if (!RegisterClass(&wnd)) { return FALSE; } hWndMain = CreateWindow("generic","简单的窗口演示程序",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL,hInstance,NULL); ShowWindow(hWndMain,nCmdShow); UpdateWindow(hWndMain); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc (HWND hwnd,UINT message,WPARAM wParam, LPARAM lParam) {HDC hdc; PAINTSTRUCT ps; char *hello = "这是一个Windows模块程序!"; char Buffer[256]; int x,y; switch(message) { case WM_PAINT: hdc = BeginPaint(hwnd,&ps); TextOut(hdc,20,10,hello,lstrlen(hello)); EndPaint(hwnd,&ps); break; case WM_CHAR: hdc = GetDC(hwnd); sprintf(Buffer," "); TextOut(hdc,0,0,Buffer,strlen(Buffer)); sprintf(Buffer,"%c",wParam); TextOut(hdc,0,0,Buffer,strlen(Buffer)); ReleaseDC(hwnd,hdc); break; case WM_LBUTTONDOWN: hdc = GetDC(hwnd); x = LOWORD(lParam); y = HIWORD(lParam); Ellipse(hdc,x-10,y-10,x+10,y+10); break; case WM_DESTROY: PostQuitMessage(0); break; default: return(DefWindowProc(hwnd,message,wParam,lParam)); } return(0); }编译没问题,但是运行时总是出错:
程序代码:
--------------------Configuration: generic - Win32 Debug-------------------- Linking... LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/generic.exe : fatal error LNK1120: 1 unresolved externals 执行 link.exe 时出错. generic.exe - 1 error(s), 0 warning(s)谁能告诉我这个问题出在哪?有没有类似其他的出错信息,一起告诉我