鱼C论坛

 找回密码
 立即注册
查看: 2044|回复: 3

[已解决]WndProc无法解析的外部函数

[复制链接]
发表于 2018-8-15 16:48:05 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 Croper 于 2018-8-15 16:50 编辑

我按第三课几乎是原样抄下来的window窗口程序,为什么一调试就报错:
【错误        LNK2019        无法解析的外部符号 "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z),该符号在函数 _WinMain@16 中被引用】


                               
登录/注册后可看大图

如图,网上也找了方案,什么把链接器里的子系统改成windows,什么添加#include<mmsystem.h>
#pragma comment(lib,"winmm.lib") ,都没用- -。这个没解决怎么往下面学啊0 0

附:源代码
  1. #include <windows.h>
  2. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

  3. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevinstance, PSTR szCmdLine, int iCmdShow)
  4. {
  5.         static TCHAR szAppName[] = TEXT("MyWindows");
  6.         HWND hwnd;
  7.         MSG msg;
  8.         WNDCLASS wndclass;

  9.         wndclass.style = CS_HREDRAW | CS_VREDRAW;
  10.         wndclass.lpfnWndProc = WndProc;
  11.         wndclass.cbClsExtra = 0;
  12.         wndclass.cbWndExtra = 0;
  13.         wndclass.hInstance = hInstance;
  14.         wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  15.         wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  16.         wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  17.         wndclass.lpszMenuName = NULL;
  18.         wndclass.lpszClassName = szAppName;

  19.         if (!RegisterClass(&wndclass))
  20.         {
  21.                 MessageBox(NULL, TEXT("这个程序需要在Windows NT环境下运行!"), szAppName, MB_ICONERROR);
  22.                 return 0;
  23.         }

  24.         hwnd = CreateWindow(szAppName,
  25.                 TEXT("Window A"),
  26.                 WS_OVERLAPPEDWINDOW,
  27.                 CW_USEDEFAULT,
  28.                 CW_USEDEFAULT,
  29.                 CW_USEDEFAULT,
  30.                 CW_USEDEFAULT,
  31.                 NULL,
  32.                 NULL,
  33.                 hInstance,
  34.                 NULL);

  35.         ShowWindow(hwnd, iCmdShow);
  36.         UpdateWindow(hwnd);

  37.         while (GetMessage(&msg, NULL, 0, 0))
  38.         {
  39.                 TranslateMessage(&msg);
  40.                 DispatchMessage(&msg);
  41.         }

  42.         return msg.wParam;



  43. }

复制代码
最佳答案
2018-8-15 16:51:15
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//本体哪里去了?

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevinstance, PSTR szCmdLine, int iCmdShow)
{
        static TCHAR szAppName[] = TEXT("MyWindows");
        HWND hwnd;
        MSG msg;
        WNDCLASS wndclass;

        wndclass.style = CS_HREDRAW | CS_VREDRAW;
        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("这个程序需要在Windows NT环境下运行!"), szAppName, MB_ICONERROR);
                return 0;
        }

        hwnd = CreateWindow(szAppName,
                TEXT("Window A"),
                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;



}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-8-15 16:51:15 | 显示全部楼层    本楼为最佳答案   
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//本体哪里去了?

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevinstance, PSTR szCmdLine, int iCmdShow)
{
        static TCHAR szAppName[] = TEXT("MyWindows");
        HWND hwnd;
        MSG msg;
        WNDCLASS wndclass;

        wndclass.style = CS_HREDRAW | CS_VREDRAW;
        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("这个程序需要在Windows NT环境下运行!"), szAppName, MB_ICONERROR);
                return 0;
        }

        hwnd = CreateWindow(szAppName,
                TEXT("Window A"),
                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;



}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-8-15 17:00:48 | 显示全部楼层
好吧好吧。。我还以为WndProc()是windows.h里自带的。。
不过想一想,自带的也不会把声明写在定义后头。。还是我太心急了0 0
谢了~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-15 17:19:03 | 显示全部楼层
Croper 发表于 2018-8-15 17:00
好吧好吧。。我还以为WndProc()是windows.h里自带的。。
不过想一想,自带的也不会把声明写在定义后头。 ...

DefWindowProc好像才是吧?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-19 12:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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