我在VC6.0中新建了一个window.c文件。程序如下:
#include<windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="窗口";
char lpszTitle[]="窗口示例"; wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd=CreateWindow(lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
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)
{
switch(message){
case WM_DESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return (0);
}
为什么编译成功,可是却执行不了?有如下提示LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/WINDOW.exe : fatal error LNK1120: 1 unresolved externals
难道VC6.0在不可以从底层开发么?只能用MFC?是不是必须在SDK中执行这个程序那?
SDK上哪里可以弄到那?????????谢谢!!!!!!!!
#include<windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="窗口";
char lpszTitle[]="窗口示例"; wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd=CreateWindow(lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
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)
{
switch(message){
case WM_DESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return (0);
}
为什么编译成功,可是却执行不了?有如下提示LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/WINDOW.exe : fatal error LNK1120: 1 unresolved externals
难道VC6.0在不可以从底层开发么?只能用MFC?是不是必须在SDK中执行这个程序那?
SDK上哪里可以弄到那?????????谢谢!!!!!!!!
我估计是你把工程类型搞错了。
你是不是选择了Win32 Console类型,应该选择Win32类型(不带Console)VC可以当作普通的C++开发环境,可以进行底层的开发。
Win32 application.new a win32 project and copy this code here
//#include "stdafx.h"#include <windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HWND hwnd;int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="窗口";
char lpszTitle[]="窗口示例"; wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = ( HBRUSH )GetStockObject( WHITE_BRUSH );
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd=CreateWindow(lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
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)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
break;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/WINDOW.exe : fatal error LNK1120: 1 unresolved externals
这个错误是说找不到程序入口;main();像sjsj(悠行者) 说的那样,就可以了
我的问题解决了
我开始的时候就是新建了一个window.c的C语言文件。没有新建工程。所以出现了哪个错误。后来我建立了一个Win32类型的工程,就像 sjsj(悠行者) 说的:选择Win32类型(不带Console)
不过我不知道为什么。我是一个菜鸟。不太了解windows机制,请大家给我解释解释一下好么?
还有, Win32 Console类型和Win32类型有什么区别?还有,为什么必须建工程?
谢谢!
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,
LPSTR lpszCmdLine, int nCmdShow)
改成int WINAPI Main(HINSTANCE hInstance,HINSTANCE hPrevInst,
LPSTR lpszCmdLine, int nCmdShow) 就行了么?