我在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上哪里可以弄到那?????????谢谢!!!!!!!!

解决方案 »

  1.   

    看你的程序没有问题
    我估计是你把工程类型搞错了。
    你是不是选择了Win32 Console类型,应该选择Win32类型(不带Console)VC可以当作普通的C++开发环境,可以进行底层的开发。
      

  2.   

    you created the project as a console application instead of a
    Win32 application.new a win32 project and copy this code here
      

  3.   

    Project Settings --> Link --> Link Options --> /subsystem:windows
      

  4.   

    你创建一个winew application 然后把代码拷贝过去就行了:)
      

  5.   

    你的程序已经改正好了,如何编译如上面说的,你的while( GetMessage( ... ) )后面多了一个;,这样你的程序就不能相应消息了// tttttt.cpp : Defines the entry point for the application.
    //#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);
    }
      

  6.   

    你的程序while( GetMessage( ... ) )后面多了一个;
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/WINDOW.exe : fatal error LNK1120: 1 unresolved externals
    这个错误是说找不到程序入口;main();像sjsj(悠行者) 说的那样,就可以了
      

  7.   

    谢谢大家
    我的问题解决了
    我开始的时候就是新建了一个window.c的C语言文件。没有新建工程。所以出现了哪个错误。后来我建立了一个Win32类型的工程,就像 sjsj(悠行者) 说的:选择Win32类型(不带Console)
    不过我不知道为什么。我是一个菜鸟。不太了解windows机制,请大家给我解释解释一下好么?
    还有, Win32 Console类型和Win32类型有什么区别?还有,为什么必须建工程?
    谢谢!
      

  8.   

    Win32 Console Application 的入口函数为 main , Win32 Application 的入口函数为 WinMain,此外区别不大
      

  9.   

    那也就是说如果我选Win32 Console Application ,只要把
        int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,
       LPSTR     lpszCmdLine, int       nCmdShow)
    改成int WINAPI Main(HINSTANCE hInstance,HINSTANCE hPrevInst,
           LPSTR     lpszCmdLine, int       nCmdShow) 就行了么?