下面的程序我是按照书敲入的,但不知为什么不能运行,总显示下列错误:Compiling...
HelloWord.cpp
c:\program files\microsoft visual studio\vc98\include\basetsd.h(3) : fatal error C1071: unexpected end of file found in comment
Error executing cl.exe.HelloWord.exe - 1 error(s), 0 warning(s)请朋友们帮帮我,谢谢了。//HelloWord.c
#include <windows.h>//窗口函数声明
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);//以下代码初始化窗口类
int WinMain(HINSTANCE hInstance,
            HINSTANCE hPrevInstance,
            LPSTR szCmdLine,
            int iCmdShow)
{
    //窗口类名
    static TCHAR szAppName[] = TEXT("HelloWorld");
    //窗口标题名
    static TCHAR lpszTitle[] = TEXT("MY First Windows Program");
    HWND      hwnd;
    MSG       msg;
    WNDCLASS  wndclass;
    //窗口类风格
    wndclass.style = CS_HREDRAW|CS_VREDRAW;
    //窗口处理函数为WndProc
    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 = szAppName;
    //如果注册失败则发出警告声
    if(!RegisterClass(&wndclass)
    {
        MessageBox(NULL,
                   TEXT("This Program requires Windows NT!"),
                   szAppName,
                   MB_ICONERROR);
        return 0;
    }
    hwnd = CreateWindow(szAppName,
                        TEXT("The Hello Program"),
                        WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        NULL,
                        NULL,
                        hInstance,
                        NULL);
    //显示窗口
    ShowWindow(hwnd,iCmdShow);
    //绘制用户区
    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)
{
    HDC         hdc;
    PAINTSTRUCT ps;
    RECT        rect;
    //消息处理语句
    switch (message)
    {
    case WM_CREATE:
        playSound(TEXT("helloworld.wav"),
                  NULL,
                  SND_FILENAME|SND_ASYNC);
        return 0 ;
    //当客户区的一部分或全部变为无效以致必须刷新时,将由这个消息通知程序
    case WM_PAINT:
        hdc = BeginPaint(hwnd,&ps);
        GetClientRect(hwnd,&rect);
        DrawText(hdc,
                 TEXT("Hello World!"),
                 l,
                 &rect,
                 DT_SINGLELINE|DT_CENTER|DT_VCENTER);
        EndPaint(hwnd,&ps);
        return 0;
    //退出窗口
    case WM_DESTROY:
        //调用PostQuitMessage函数发出WM_QUIT消息
        PostQuitMessage(0); 
        return 0;
    }
    return DefWindowProc(hwnd,message,wParam,lParam);
}

解决方案 »

  1.   

    //HelloWord.c
    #include <windows.h>
    #include <mmsystem.h>
    //窗口函数声明
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);//以下代码初始化窗口类
    __stdcall WinMain(HINSTANCE hInstance,
                HINSTANCE hPrevInstance,
                LPSTR szCmdLine,
                int iCmdShow)
    {
        //窗口类名
        static TCHAR szAppName[] = TEXT("HelloWorld");
        //窗口标题名
        static TCHAR lpszTitle[] = TEXT("MY First Windows Program");
        HWND      hwnd;
        MSG       msg;
        WNDCLASS  wndclass;
        //窗口类风格
        wndclass.style = CS_HREDRAW|CS_VREDRAW;
        //窗口处理函数为WndProc
        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 = szAppName;
        //如果注册失败则发出警告声
        if(!RegisterClass(&wndclass))
        {
            MessageBox(NULL,
                       TEXT("This Program requires Windows NT!"),
                       szAppName,
                       MB_ICONERROR);
            return 0;
        }
        hwnd = CreateWindow(szAppName,
                            TEXT("The Hello Program"),
                            WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            NULL,
                            NULL,
                            hInstance,
                            NULL);
        //显示窗口
        ShowWindow(hwnd,iCmdShow);
        //绘制用户区
        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)
    {
        HDC         hdc;
        PAINTSTRUCT ps;
        RECT        rect;
        //消息处理语句
        switch (message)
        {
        case WM_CREATE:
            PlaySound(TEXT("helloworld.wav"),
                      NULL,
                      SND_FILENAME|SND_ASYNC);
            return 0 ;
        //当客户区的一部分或全部变为无效以致必须刷新时,将由这个消息通知程序
        case WM_PAINT:
            hdc = BeginPaint(hwnd,&ps);
            GetClientRect(hwnd,&rect);
            DrawText(hdc,
                     TEXT("Hello World!"),
                     1,
                     &rect,
                     DT_SINGLELINE|DT_CENTER|DT_VCENTER);
            EndPaint(hwnd,&ps);
            return 0;
        //退出窗口
        case WM_DESTROY:
            //调用PostQuitMessage函数发出WM_QUIT消息
            PostQuitMessage(0); 
            return 0;
        }
        return DefWindowProc(hwnd,message,wParam,lParam);
    }你不是用的WinAPP
      

  2.   

    对,不是用的WinAPP,我直接把代码敲入的。
      

  3.   

    加上了#include <mmsystem.h>语句还是不运行。
      

  4.   

    还有那个在setting里面的link加上winmm.lib 这个东西你新建工程应该建<Win32 App>
      

  5.   

    我选择的是新建工程,点击Win32 Application选项。
    然后我直接把代码敲入的。
      

  6.   

    你的代码有几处错误:
    1。//如果注册失败则发出警告声
        if(!RegisterClass(&wndclass)//少了一个右括号,不仔细噢 :)
    2。case WM_PAINT:
            hdc = BeginPaint(hwnd,&ps);
            GetClientRect(hwnd,&rect);
            DrawText(hdc,
                     TEXT("Hello World!"),
                     l,//为改为-1
                     &rect,
                     DT_SINGLELINE|DT_CENTER|DT_VCENTER);
            EndPaint(hwnd,&ps);
            return 0;
        
        
    3。case WM_CREATE:
            //PlaySound(TEXT("helloworld.wav"),//这里你你调用了一个多媒体的函数你把这一句注释掉看看,要不你要加入一个什么多媒体的什么联接库的。具体我忘了。
            //          NULL,
             //         SND_FILENAME|SND_ASYNC);
            return 0 ;
      

  7.   

    将上述错误修改后,还是不能通过编译,还是显示下述信息:
    --------------------Configuration: HelloWorld - Win32 Debug--------------------
    Compiling...
    HelloWorld.cpp
    c:\program files\microsoft visual studio\vc98\include\basetsd.h(3) : fatal error C1071: unexpected end of file found in comment
    Error executing cl.exe.HelloWorld.exe - 1 error(s), 0 warning(s)
      

  8.   

    我真搞不懂,下述程序到底错在哪?为什么总是出下述信息:
    --------------------Configuration: HelloWorld - Win32 Debug--------------------
    Compiling...
    HelloWorld.cpp
    c:\program files\microsoft visual studio\vc98\include\basetsd.h(3) : fatal error C1071: unexpected end of file found in comment
    Error executing cl.exe.HelloWorld.exe - 1 error(s), 0 warning(s)
    那个“error C1071”到底是什么?//HelloWorld.cpp
    #include <windows.h>
    #include <mmsystem.h>
    #pragma comment ( lib, "Winmm.lib" )//窗口函数声明
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);//以下代码初始化窗口类
    int WinMain(HINSTANCE hInstance,
                HINSTANCE hPrevInstance,
                LPSTR szCmdLine,
                int iCmdShow)
    {
        //窗口类名
        static TCHAR szAppName[] = TEXT("HelloWorld");
        //窗口标题名
        static TCHAR lpszTitle[] = TEXT("MY First Windows Program");
        HWND      hwnd;
        MSG       msg;
        WNDCLASS  wndclass;
        //窗口类风格
        wndclass.style = CS_HREDRAW|CS_VREDRAW;
        //窗口处理函数为WndProc
        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 = szAppName;
        //如果注册失败则发出警告声
        if(!RegisterClass(&wndclass))
        {
            MessageBox(NULL,
                       TEXT("This Program requires Windows NT!"),
                       szAppName,
                       MB_ICONERROR);
            return 0;
        }
        hwnd = CreateWindow(szAppName,
                            TEXT("The Hello Program"),
                            WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            NULL,
                            NULL,
                            hInstance,
                            NULL);
        //显示窗口
        ShowWindow(hwnd,iCmdShow);
        //绘制用户区
        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)
    {
        HDC         hdc;
        PAINTSTRUCT ps;
        RECT        rect;
        //消息处理语句
        switch (message)
        {
        case WM_CREATE:
            //playSound(TEXT("helloworld.wav"),
            //          NULL,
            //          SND_FILENAME|SND_ASYNC);
            return 0 ;
        //当客户区的一部分或全部变为无效以致必须刷新时,将由这个消息通知程序
        case WM_PAINT:
            hdc = BeginPaint(hwnd,&ps);
            GetClientRect(hwnd,&rect);
            DrawText(hdc,
                     TEXT("Hello World!"),
                     -l,
                     &rect,
                     DT_SINGLELINE|DT_CENTER|DT_VCENTER);
            EndPaint(hwnd,&ps);
            return 0;
        //退出窗口
        case WM_DESTROY:
            //调用PostQuitMessage函数发出WM_QUIT消息
            PostQuitMessage(0); 
            return 0;
        }
        return DefWindowProc(hwnd,message,wParam,lParam);
    }
      

  9.   

    你得程序错误地方如下:
    1。if(!RegisterClass(&wndclass))最后少右括号
    2。PlaySound(TEXT("helloworld.wav"),得“p”是大写得。
    3。TEXT("Hello World!"),
                     l,//改成-1
    4。在菜单project->settings->link页的object/library modules的最后加上winmm.lib,与以前都用空格格开。下面是正确的代码(新建win32 app就可以啦)
    #include <windows.h>//窗口函数声明
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);//以下代码初始化窗口类
    int WinMain(HINSTANCE hInstance,
                HINSTANCE hPrevInstance,
                LPSTR szCmdLine,
                int iCmdShow)
    {
        //窗口类名
        static TCHAR szAppName[] = TEXT("HelloWorld");
        //窗口标题名
        static TCHAR lpszTitle[] = TEXT("MY First Windows Program");
        HWND      hwnd;
        MSG       msg;
        WNDCLASS  wndclass;
        //窗口类风格
        wndclass.style = CS_HREDRAW|CS_VREDRAW;
        //窗口处理函数为WndProc
        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 = szAppName;
        //如果注册失败则发出警告声
        if(!RegisterClass(&wndclass))
        {
            MessageBox(NULL,
                       TEXT("This Program requires Windows NT!"),
                       szAppName,
                       MB_ICONERROR);
            return 0;
        }
        hwnd = CreateWindow(szAppName,
                            TEXT("The Hello Program"),
                            WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            NULL,
                            NULL,
                            hInstance,
                            NULL);
        //显示窗口
        ShowWindow(hwnd,iCmdShow);
        //绘制用户区
        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)
    {
        HDC         hdc;
        PAINTSTRUCT ps;
        RECT        rect;
        //消息处理语句
        switch (message)
        {
        case WM_CREATE:
            
    PlaySound(TEXT("helloworld.wav"),
                      NULL,
                      SND_FILENAME|SND_ASYNC);
            return 0 ;
        //当客户区的一部分或全部变为无效以致必须刷新时,将由这个消息通知程序
        case WM_PAINT:
            hdc = BeginPaint(hwnd,&ps);
            GetClientRect(hwnd,&rect);
            DrawText(hdc,
                     TEXT("Hello World!"),
                     -1,
                     &rect,
                     DT_SINGLELINE|DT_CENTER|DT_VCENTER);
            EndPaint(hwnd,&ps);
            return 0;
        //退出窗口
        case WM_DESTROY:
            //调用PostQuitMessage函数发出WM_QUIT消息
            PostQuitMessage(0); 
            return 0;
        }
        return DefWindowProc(hwnd,message,wParam,lParam);
    }
      

  10.   

    谢谢,修改后,本程序在WINXP下可以运行了;但在WINME下还是不可运行。
    另外,为什么要把“1”改为“-1”?请教了,谢谢!