source files 中有 GENERIC.C  GENERIC.RC 两个文件,header files 中有GENERIC.H  RESOURCE.H 两个文件,代码如下,编译执行后出现如下错误信息:generic.c(139) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.//--------------------generic.h--------------------------------
BOOL InitApplication(HANDLE);
BOOL InitInstance(HANDLE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
//-------------------------GENERIC.C---------------------------#include <windows.h>   
#include "resource.h" 
#include "generic.h"  
HINSTANCE _hInst;     
HWND      _hWnd;char _szAppName[] = "Generic";  
char _szTitle[]   = "Generic Sample Application"; 
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                     LPSTR lpCmdLine,     int nCmdShow)
{
MSG msg;  UNREFERENCED_PARAMETER(lpCmdLine);      if (!hPrevInstance)
      if (!InitApplication(hInstance))
          return (FALSE);  if (!InitInstance(hInstance, nCmdShow))
      return (FALSE);  while (GetMessage(&msg, NULL, 0, 0)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
  }  return (msg.wParam); 
}BOOL InitApplication(HINSTANCE hInstance)
{
WNDCLASS  wc;  wc.style         = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc   = (WNDPROC)WndProc;    
  wc.cbClsExtra    = 0;
  wc.cbWndExtra    = 0;
  wc.hInstance     = hInstance;
  wc.hIcon         = LoadIcon(hInstance, "jjhouricon");
  wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = GetStockObject(WHITE_BRUSH);  
  wc.lpszMenuName  = "GenericMenu";                
  wc.lpszClassName = _szAppName;  return (RegisterClass(&wc));
}BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
  _hInst = hInstance;   _hWnd = CreateWindow(
                       _szAppName,
                       _szTitle,
                       WS_OVERLAPPEDWINDOW,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       NULL,
                       NULL,
                       hInstance,
                       NULL
                      );  if (!_hWnd)
      return (FALSE);  ShowWindow(_hWnd, nCmdShow);
  UpdateWindow(_hWnd);         
  return (TRUE);
}LRESULT CALLBACK WndProc(HWND hWnd,     UINT message,
                         WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;  switch (message) {
    case WM_COMMAND:         wmId    = LOWORD(wParam);
         wmEvent = HIWORD(wParam);         switch (wmId) {
           case IDM_ABOUT:
                DialogBox(_hInst,
                          "AboutBox",    
                          hWnd,          
                          (DLGPROC)About 
                         );
                break;           case IDM_EXIT:
               
                DestroyWindow (hWnd);
                break;           default:
                return (DefWindowProc(hWnd, message, wParam, lParam));
         }
         break;    case WM_DESTROY:  
         PostQuitMessage(0);
         break;    default:
         return (DefWindowProc(hWnd, message, wParam, lParam));
  }
  return (0);
}LRESULT CALLBACK About(HWND hDlg,     UINT message,
                       WPARAM wParam, LPARAM lParam)
{
  UNREFERENCED_PARAMETER(lParam);        switch (message) {
    case WM_INITDIALOG:
         return (TRUE);         case WM_COMMAND:
         if (LOWORD(wParam) == IDOK
             || LOWORD(wParam) == IDCANCEL) {
             EndDialog(hDlg, TRUE);
             return (TRUE); 
         }
         break;
  }
  return (FALSE); 
}
//------------------------------generic.rc--------------------------
#include "windows.h"
#include "resource.h"jjhouricon ICON    DISCARDABLE     "jjhour.ico"GenericMenu MENU DISCARDABLE
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "&New",              IDM_NEW, GRAYED
        MENUITEM "&Open...",          IDM_OPEN, GRAYED
        MENUITEM "&Save",             IDM_SAVE, GRAYED
        MENUITEM "Save &As...",       IDM_SAVEAS, GRAYED
        MENUITEM SEPARATOR
        MENUITEM "&Print...",         IDM_PRINT, GRAYED
        MENUITEM "P&rint Setup...",   IDM_PRINTSETUP, GRAYED
        MENUITEM SEPARATOR
        MENUITEM "E&xit",             IDM_EXIT
    END
    POPUP "&Edit"
    BEGIN
        MENUITEM "&Undo\tCtrl+Z",     IDM_UNDO, GRAYED
        MENUITEM SEPARATOR
        MENUITEM "Cu&t\tCtrl+X",      IDM_CUT, GRAYED
        MENUITEM "&Copy\tCtrl+C",     IDM_COPY, GRAYED
        MENUITEM "&Paste\tCtrl+V",    IDM_PASTE, GRAYED
        MENUITEM "Paste &Link",       IDM_LINK, GRAYED
        MENUITEM SEPARATOR
        MENUITEM "Lin&ks...",         IDM_LINKS, GRAYED
    END
    POPUP "&Help"
    BEGIN
        MENUITEM "&Contents",               IDM_HELPCONTENTS, GRAYED
        MENUITEM "&Search for Help On...",  IDM_HELPSEARCH, GRAYED
        MENUITEM "&How to Use Help",        IDM_HELPHELP, GRAYED
        MENUITEM SEPARATOR
        MENUITEM "&About Generic...",       IDM_ABOUT
    END
ENDAboutBox DIALOG DISCARDABLE  22, 17, 144, 75
STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
CAPTION "About Generic"
BEGIN
    CTEXT           "Windows 95",         -1,0, 5,144,8
    CTEXT           "Generic Application",-1,0,14,144,8
    CTEXT           "Version 1.0",        -1,0,34,144,8
    DEFPUSHBUTTON   "OK",              IDOK,53,59,32,14,WS_GROUP
END//---------------------resource.h---------------------
#define IDM_NEW                         40001
#define IDM_OPEN                        40002
#define IDM_SAVE                        40003
#define IDM_SAVEAS                      40004
#define IDM_PRINT                       40005
#define IDM_PRINTSETUP                  40006
#define IDM_EXIT                        40007
#define IDM_UNDO                        40008
#define IDM_CUT                         40009
#define IDM_COPY                        40010
#define IDM_PASTE                       40011
#define IDM_LINK                        40012
#define IDM_LINKS                       40013
#define IDM_HELPCONTENTS                40014
#define IDM_HELPSEARCH                  40015
#define IDM_HELPHELP                    40016
#define IDM_ABOUT                       40017

解决方案 »

  1.   

    该例有 MAKE 文件,怎样才能使它在VC++6.0中编译OK呢?请指教
    代码如下:# filename : generic.mak
    # make file for generic.exe (Generic Windows Application)
    # usage : nmake generic.mak (Microsoft C/C++ 9.00) (Visual C++ 2.0)
    # usage : nmake generic.mak (Microsoft C/C++ 10.00) (Visual C++ 4.0)all: generic.exegeneric.res : generic.rc generic.h
        rc generic.rcgeneric.obj : generic.c generic.h
        cl -c -W3 -Gz -D_X86_ -DWIN32 generic.cgeneric.exe : generic.obj generic.res
        link /MACHINE:I386 -subsystem:windows generic.res generic.obj \
             libc.lib kernel32.lib user32.lib gdi32.lib
      

  2.   

    方法1:在那个出错的c/cpp文件的开始加入一行
    #inclue "stdafx.h"方法2:选菜单Project|Setting,在对话框的左边的Source Files里找到出错的那个c/cpp文件,
    在右边选C/C++,在Category列表框里选Precompiled Headers,然后在下面选Not using precompiled headers.
      

  3.   

    使用方法2后的错误信息:
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__DispatchMessageA@4
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__TranslateMessage@4
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__GetMessageA@16
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__RegisterClassA@4
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__GetStockObject@4
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__LoadCursorA@8
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__LoadIconA@8
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__UpdateWindow@4
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__ShowWindow@8
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__CreateWindowExA@48
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__PostQuitMessage@4
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__DefWindowProcA@16
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__DestroyWindow@4
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__DialogBoxParamA@20
    GENERIC.OBJ : error LNK2001: unresolved external symbol __imp__EndDialog@8
    Debug/1.exe : fatal error LNK1120: 15 unresolved externals
      

  4.   

    问题当然是缺少相应的库文件了。
    你在源文件加入一行
    #pragma comment(lib,"user32.lib")
    看看行不行。
      

  5.   

    第一种也试了,加了 stdafx.h  stdafx.cpp文件,和#inclue "stdafx.h" 可能是哪儿没注意到
    错误信息为: fatal error C1083: Cannot open include file: 'StdAfx.h': No such file or directory