我试着在VISUAL C++ 6。0下输入了下列程序,按照书上写的程序的说明,应当是能够在屏幕上建立并显示一个空白的窗口。我在把程序输入以后,编译能够通过,但是当我选择运行是,就有两个错,我不知道应当如何解决。是我的程序输入有什么问题,还是我在编译是需要什么步骤,请指点。
下附程序的代码和编译是的信息。
程序代码
#include<windows.h>LRESULT CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);char szWinName[] = "MyWin";int PASCAL WinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,LPSTR IpszArgs,int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASS wcl; wcl.hInstance = hThisInst;
wcl.lpszClassName = szWinName;
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wcl.hCursor = LoadCursor(NULL,IDC_ARROW);
wcl.lpszMenuName = NULL; wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0; wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); if(!RegisterClass (&wcl)) return 0;
hwnd = CreateWindow(
szWinName,
"Windows 98 Framwork",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL
); ShowWindow(hwnd,nWinMode);
UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}LRESULT CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}编译信息:
Build Log--------------------Configuration: Frame - Win32 Debug--------------------Command Lines
Creating temporary file "D:\WINDOWS\TEMP\RSP50D3.TMP" with contents
[
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/Frame.pdb" /debug /machine:I386 /out:"Debug/Frame.exe" /pdbtype:sept
".\Debug\Frame.obj"
]
Creating command line "link.exe @D:\WINDOWS\TEMP\RSP50D3.TMP"
Output Window
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Frame.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.Results
Frame.exe - 2 error(s), 0 warning(s)
下附程序的代码和编译是的信息。
程序代码
#include<windows.h>LRESULT CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);char szWinName[] = "MyWin";int PASCAL WinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,LPSTR IpszArgs,int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASS wcl; wcl.hInstance = hThisInst;
wcl.lpszClassName = szWinName;
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wcl.hCursor = LoadCursor(NULL,IDC_ARROW);
wcl.lpszMenuName = NULL; wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0; wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); if(!RegisterClass (&wcl)) return 0;
hwnd = CreateWindow(
szWinName,
"Windows 98 Framwork",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL
); ShowWindow(hwnd,nWinMode);
UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}LRESULT CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}编译信息:
Build Log--------------------Configuration: Frame - Win32 Debug--------------------Command Lines
Creating temporary file "D:\WINDOWS\TEMP\RSP50D3.TMP" with contents
[
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/Frame.pdb" /debug /machine:I386 /out:"Debug/Frame.exe" /pdbtype:sept
".\Debug\Frame.obj"
]
Creating command line "link.exe @D:\WINDOWS\TEMP\RSP50D3.TMP"
Output Window
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Frame.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.Results
Frame.exe - 2 error(s), 0 warning(s)
再次选择New,创建一个新的C++ Source File。把你的代码Copy进去,编译运行!