鱼C论坛

 找回密码
 立即注册
查看: 2963|回复: 9

正在学孙鑫的“VC++深入理解”,为什么书第二章附码的解决方案可以编译,而我按书...

[复制链接]
发表于 2021-4-5 08:49:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
不编译就显示的错误:
严重性    代码    说明    项目    文件    行    禁止显示状态
错误(活动)    E1097    未知特性 "no_init_all"    WinMain    E:\Windows Kits\10\Include\10.0.18362.0\um\winnt.h    3886   


编译后增加两条:
1:
严重性    代码    说明    项目    文件    行    禁止显示状态
错误    LNK2001    无法解析的外部符号 main    WinMain    D:\VS2019工作目录\Windows程序练习\VC++深入理解\Practice\ch02\WinMain_Build\ch02\WinMain\MSVCRT.lib(exe_main.obj)    1   

2:
严重性    代码    说明    项目    文件    行    禁止显示状态
错误    LNK1120    1 个无法解析的外部命令    WinMain    D:\VS2019工作目录\Windows程序练习\VC++深入理解\Practice\ch02\WinMain_Build\ch02\x64\Release\WinMain.exe    1   
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-5 09:08:12 From FishC Mobile | 显示全部楼层
这个问题需要你自行研究
首先你没发代码,鬼都不晓得你在讲什么

其次,即使你发出代码,估计也没人会
现在研究mfc的好像不多
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-5 09:30:43 | 显示全部楼层
源码:
#include <windows.h>
#include <stdio.h>



LRESULT CALLBACK WinSunProc(
        HWND hwnd,                  // handle to window
        UINT uMsg,                    // message identifier
        WPARAM wParam,        // first message parameter
        LPARAM lParam                 // second message parameter
);

int WINAPI WinMain(
        HINSTANCE hInstance,                  // handle to current instance
        HINSTANCE hPrevInstance,                // handle to previous instance
        LPSTR lpCmdLine,                       // command line
        int nCmdShow                                   // show state
)
{
        //设计一个窗口类
        WNDCLASS wndcls;
        wndcls.cbClsExtra = 0;
        wndcls.cbWndExtra = 0;
        wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
        wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
        wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);
        wndcls.hInstance = hInstance;                //应用程序实例句柄由WinMain函数传进来
        wndcls.lpfnWndProc = WinSunProc;
        wndcls.lpszClassName = "sunxin2019";
        wndcls.lpszMenuName = NULL;
        wndcls.style = CS_HREDRAW | CS_VREDRAW;
        RegisterClass(&wndcls);

        //创建窗口,定义一个变量用来保存成功创建窗口后返回的句柄
        HWND hwnd;
        hwnd = CreateWindow("sunxin2019", "http://www.phei.com.cn",
                WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);

        //显示及刷新窗口
        ShowWindow(hwnd, SW_SHOWNORMAL);
        UpdateWindow(hwnd);

        //定义消息结构体,开始消息循环
        MSG msg;
        BOOL bRet;
        //while (GetMessage(&msg, NULL, 0, 0))
        while ((bRet = GetMessage(&msg, hwnd, 0, 0)) != 0)
        {
                if (bRet == -1)
                {
                        // handle the error and possibly exit
                        return -1;
                }
                else
                {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                }


        }
        return msg.wParam;
}

//编写窗口过程函数
LRESULT CALLBACK WinSunProc(
        HWND hwnd,                  // handle to window
        UINT uMsg,                   // message identifier
        WPARAM wParam,        // first message parameter
        LPARAM lParam                 // second message parameter
)
{
        switch (uMsg)
        {
        case WM_CHAR:
                char szChar[20];
                sprintf_s(szChar, sizeof(szChar), "char code is %d", wParam);
                MessageBox(hwnd, szChar, "char", 0);
                break;
        case WM_LBUTTONDOWN:
                MessageBox(hwnd, "mouse clicked", "message", 0);
                HDC hdc;
                hdc = GetDC(hwnd);                //不能在响应WM_PAINT消息时调用
                TextOut(hdc, 0, 50, "程序员之家", strlen("程序员之家"));
                ReleaseDC(hwnd, hdc);
                break;
        case WM_PAINT:
                HDC hDC;
                PAINTSTRUCT ps;
                hDC = BeginPaint(hwnd, &ps);                //BeginPaint只能在响应WM_PAINT消息时调用
                TextOut(hDC, 0, 0, "http://www.phei.com.cn", strlen("http://www.phei.com.cn"));
                EndPaint(hwnd, &ps);
                break;
        case WM_CLOSE:
                if (IDYES == MessageBox(hwnd, "是否真的结束?", "message", MB_YESNO))
                {
                        DestroyWindow(hwnd);
                }
                break;
        case WM_DESTROY:
                PostQuitMessage(0);
                break;
        default:
                return DefWindowProc(hwnd, uMsg, wParam, lParam);
        }
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-5 09:31:55 | 显示全部楼层
我感觉我的和书附码一模一样,不知道哪个细节出了问题
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-5 09:39:42 | 显示全部楼层
源码:
#include <windows.h>
#include <stdio.h>



LRESULT CALLBACK WinSunProc(
        HWND hwnd,                  // handle to window
        UINT uMsg,                    // message identifier
        WPARAM wParam,        // first message parameter
        LPARAM lParam                 // second message parameter
);

int WINAPI WinMain(
        HINSTANCE hInstance,                  // handle to current instance
        HINSTANCE hPrevInstance,                // handle to previous instance
        LPSTR lpCmdLine,                       // command line
        int nCmdShow                                   // show state
)
{
        //设计一个窗口类
        WNDCLASS wndcls;
        wndcls.cbClsExtra = 0;
        wndcls.cbWndExtra = 0;
        wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
        wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
        wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);
        wndcls.hInstance = hInstance;                //应用程序实例句柄由WinMain函数传进来
        wndcls.lpfnWndProc = WinSunProc;
        wndcls.lpszClassName = "sunxin2019";
        wndcls.lpszMenuName = NULL;
        wndcls.style = CS_HREDRAW | CS_VREDRAW;
        RegisterClass(&wndcls);

        //创建窗口,定义一个变量用来保存成功创建窗口后返回的句柄
        HWND hwnd;
        hwnd = CreateWindow("sunxin2019", "http://www.phei.com.cn",
                WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);

        //显示及刷新窗口
        ShowWindow(hwnd, SW_SHOWNORMAL);
        UpdateWindow(hwnd);

        //定义消息结构体,开始消息循环
        MSG msg;
        BOOL bRet;
        //while (GetMessage(&msg, NULL, 0, 0))
        while ((bRet = GetMessage(&msg, hwnd, 0, 0)) != 0)
        {
                if (bRet == -1)
                {
                        // handle the error and possibly exit
                        return -1;
                }
                else
                {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                }


        }
        return msg.wParam;
}

//编写窗口过程函数
LRESULT CALLBACK WinSunProc(
        HWND hwnd,                  // handle to window
        UINT uMsg,                   // message identifier
        WPARAM wParam,        // first message parameter
        LPARAM lParam                 // second message parameter
)
{
        switch (uMsg)
        {
        case WM_CHAR:
                char szChar[20];
                sprintf_s(szChar, sizeof(szChar), "char code is %d", wParam);
                MessageBox(hwnd, szChar, "char", 0);
                break;
        case WM_LBUTTONDOWN:
                MessageBox(hwnd, "mouse clicked", "message", 0);
                HDC hdc;
                hdc = GetDC(hwnd);                //不能在响应WM_PAINT消息时调用
                TextOut(hdc, 0, 50, "程序员之家", strlen("程序员之家"));
                ReleaseDC(hwnd, hdc);
                break;
        case WM_PAINT:
                HDC hDC;
                PAINTSTRUCT ps;
                hDC = BeginPaint(hwnd, &ps);                //BeginPaint只能在响应WM_PAINT消息时调用
                TextOut(hDC, 0, 0, "http://www.phei.com.cn", strlen("http://www.phei.com.cn"));
                EndPaint(hwnd, &ps);
                break;
        case WM_CLOSE:
                if (IDYES == MessageBox(hwnd, "是否真的结束?", "message", MB_YESNO))
                {
                        DestroyWindow(hwnd);
                }
                break;
        case WM_DESTROY:
                PostQuitMessage(0);
                break;
        default:
                return DefWindowProc(hwnd, uMsg, wParam, lParam);
        }
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-5 09:40:52 | 显示全部楼层
  1. #include <windows.h>
  2. #include <stdio.h>



  3. LRESULT CALLBACK WinSunProc(
  4.         HWND hwnd,                  // handle to window
  5.         UINT uMsg,                    // message identifier
  6.         WPARAM wParam,        // first message parameter
  7.         LPARAM lParam                 // second message parameter
  8. );

  9. int WINAPI WinMain(
  10.         HINSTANCE hInstance,                  // handle to current instance
  11.         HINSTANCE hPrevInstance,                // handle to previous instance
  12.         LPSTR lpCmdLine,                       // command line
  13.         int nCmdShow                                   // show state
  14. )
  15. {
  16.         //设计一个窗口类
  17.         WNDCLASS wndcls;
  18.         wndcls.cbClsExtra = 0;
  19.         wndcls.cbWndExtra = 0;
  20.         wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  21.         wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
  22.         wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);
  23.         wndcls.hInstance = hInstance;                //应用程序实例句柄由WinMain函数传进来
  24.         wndcls.lpfnWndProc = WinSunProc;
  25.         wndcls.lpszClassName = "sunxin2019";
  26.         wndcls.lpszMenuName = NULL;
  27.         wndcls.style = CS_HREDRAW | CS_VREDRAW;
  28.         RegisterClass(&wndcls);

  29.         //创建窗口,定义一个变量用来保存成功创建窗口后返回的句柄
  30.         HWND hwnd;
  31.         hwnd = CreateWindow("sunxin2019", "http://www.phei.com.cn",
  32.                 WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);

  33.         //显示及刷新窗口
  34.         ShowWindow(hwnd, SW_SHOWNORMAL);
  35.         UpdateWindow(hwnd);

  36.         //定义消息结构体,开始消息循环
  37.         MSG msg;
  38.         BOOL bRet;
  39.         //while (GetMessage(&msg, NULL, 0, 0))
  40.         while ((bRet = GetMessage(&msg, hwnd, 0, 0)) != 0)
  41.         {
  42.                 if (bRet == -1)
  43.                 {
  44.                         // handle the error and possibly exit
  45.                         return -1;
  46.                 }
  47.                 else
  48.                 {
  49.                         TranslateMessage(&msg);
  50.                         DispatchMessage(&msg);
  51.                 }


  52.         }
  53.         return msg.wParam;
  54. }

  55. //编写窗口过程函数
  56. LRESULT CALLBACK WinSunProc(
  57.         HWND hwnd,                  // handle to window
  58.         UINT uMsg,                   // message identifier
  59.         WPARAM wParam,        // first message parameter
  60.         LPARAM lParam                 // second message parameter
  61. )
  62. {
  63.         switch (uMsg)
  64.         {
  65.         case WM_CHAR:
  66.                 char szChar[20];
  67.                 sprintf_s(szChar, sizeof(szChar), "char code is %d", wParam);
  68.                 MessageBox(hwnd, szChar, "char", 0);
  69.                 break;
  70.         case WM_LBUTTONDOWN:
  71.                 MessageBox(hwnd, "mouse clicked", "message", 0);
  72.                 HDC hdc;
  73.                 hdc = GetDC(hwnd);                //不能在响应WM_PAINT消息时调用
  74.                 TextOut(hdc, 0, 50, "程序员之家", strlen("程序员之家"));
  75.                 ReleaseDC(hwnd, hdc);
  76.                 break;
  77.         case WM_PAINT:
  78.                 HDC hDC;
  79.                 PAINTSTRUCT ps;
  80.                 hDC = BeginPaint(hwnd, &ps);                //BeginPaint只能在响应WM_PAINT消息时调用
  81.                 TextOut(hDC, 0, 0, "http://www.phei.com.cn", strlen("http://www.phei.com.cn"));
  82.                 EndPaint(hwnd, &ps);
  83.                 break;
  84.         case WM_CLOSE:
  85.                 if (IDYES == MessageBox(hwnd, "是否真的结束?", "message", MB_YESNO))
  86.                 {
  87.                         DestroyWindow(hwnd);
  88.                 }
  89.                 break;
  90.         case WM_DESTROY:
  91.                 PostQuitMessage(0);
  92.                 break;
  93.         default:
  94.                 return DefWindowProc(hwnd, uMsg, wParam, lParam);
  95.         }
  96.         return 0;
  97. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-5 10:57:34 | 显示全部楼层
把windows sdk 版本 从 10.0.18362.0改为10.0.17763.0后,第一个错误没有了,
但第2,3个错误依然存在,大神能不能提醒一下主要修改哪些属性项?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-4-5 16:16:24 From FishC Mobile | 显示全部楼层
你的代码有 main() 函数吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-5 16:23:11 | 显示全部楼层
#include <windows.h>
#include <stdio.h>

LRESULT CALLBACK WinSunProc(
        HWND hwnd,                  // handle to window
        UINT uMsg,                    // message identifier
        WPARAM wParam,        // first message parameter
        LPARAM lParam                 // second message parameter
);

int WINAPI WinMain(
        HINSTANCE hInstance,                  // handle to current instance
        HINSTANCE hPrevInstance,                // handle to previous instance
        LPSTR lpCmdLine,                       // command line
        int nCmdShow                                   // show state
)
{
        //设计一个窗口类
        WNDCLASS wndcls;
        wndcls.cbClsExtra = 0;
        wndcls.cbWndExtra = 0;
        wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
        wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
        wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);
        wndcls.hInstance = hInstance;                //应用程序实例句柄由WinMain函数传进来
        wndcls.lpfnWndProc = WinSunProc;
        wndcls.lpszClassName = "sunxin2019";
        wndcls.lpszMenuName = NULL;
        wndcls.style = CS_HREDRAW | CS_VREDRAW;
        RegisterClass(&wndcls);
       
        //创建窗口,定义一个变量用来保存成功创建窗口后返回的句柄
        HWND hwnd;
        hwnd = CreateWindow("sunxin2019", "http://www.phei.com.cn",
                WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);

        //显示及刷新窗口
        ShowWindow(hwnd, SW_SHOWNORMAL);
        UpdateWindow(hwnd);

        //定义消息结构体,开始消息循环
        MSG msg;
        BOOL bRet;
        //while (GetMessage(&msg, NULL, 0, 0))
        while ((bRet = GetMessage(&msg, hwnd, 0, 0)) != 0)
        {
                if (bRet == -1)
                {
                        // handle the error and possibly exit
                        return -1;
                }
                else
                {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                }

               
        }
        return msg.wParam;
}

//编写窗口过程函数
LRESULT CALLBACK WinSunProc(
        HWND hwnd,                  // handle to window
        UINT uMsg,                   // message identifier
        WPARAM wParam,        // first message parameter
        LPARAM lParam                 // second message parameter
)
{
        switch (uMsg)
        {
        case WM_CHAR:
                char szChar[20];
                sprintf_s(szChar, sizeof(szChar), "char code is %d", wParam);
                MessageBox(hwnd, szChar, "char", 0);
                break;
        case WM_LBUTTONDOWN:
                MessageBox(hwnd, "mouse clicked", "message", 0);
                HDC hdc;
                hdc = GetDC(hwnd);                //不能在响应WM_PAINT消息时调用
                TextOut(hdc, 0, 50, "程序员之家", strlen("程序员之家"));
                ReleaseDC(hwnd, hdc);
                break;
        case WM_PAINT:
                HDC hDC;
                PAINTSTRUCT ps;
                hDC = BeginPaint(hwnd, &ps);                //BeginPaint只能在响应WM_PAINT消息时调用
                TextOut(hDC, 0, 0, "http://www.phei.com.cn", strlen("http://www.phei.com.cn"));
                EndPaint(hwnd, &ps);
                break;
        case WM_CLOSE:
                if (IDYES == MessageBox(hwnd, "是否真的结束?", "message", MB_YESNO))
                {
                        DestroyWindow(hwnd);
                }
                break;
        case WM_DESTROY:
                PostQuitMessage(0);
                break;
        default:
                return DefWindowProc(hwnd, uMsg, wParam, lParam);
        }
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-5 16:23:48 | 显示全部楼层
有啊:
int WINAPI WinMain(
        HINSTANCE hInstance,                  // handle to current instance
        HINSTANCE hPrevInstance,                // handle to previous instance
        LPSTR lpCmdLine,                       // command line
        int nCmdShow                                   // show state
)
{
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-7 00:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表