鱼C论坛

 找回密码
 立即注册
查看: 2916|回复: 1

[已解决]Windows(SDK)代码在vs2015运行报错LNK1120 一个无法解析的外部命令

[复制链接]
发表于 2018-1-25 19:53:23 | 显示全部楼层 |阅读模式

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

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

x
  1. #include <windows.h>

  2. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

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

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

  20.      if (!RegisterClass (&wndclass))
  21.      {
  22.           MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  23.                       szAppName, MB_ICONERROR) ;
  24.           return 0 ;
  25.      }
  26.      
  27.      hwnd = CreateWindow (szAppName,                  // window class name
  28.                           TEXT ("The Hello Program"), // window caption
  29.                           WS_OVERLAPPEDWINDOW,        // window style
  30.                           CW_USEDEFAULT,              // initial x position
  31.                           CW_USEDEFAULT,              // initial y position
  32.                           CW_USEDEFAULT,              // initial x size
  33.                           CW_USEDEFAULT,              // initial y size
  34.                           NULL,                       // parent window handle
  35.                           NULL,                       // window menu handle
  36.                           hInstance,                  // program instance handle
  37.                           NULL) ;                     // creation parameters
  38.      
  39.      ShowWindow (hwnd, iCmdShow) ;
  40.      UpdateWindow (hwnd) ;
  41.      
  42.      while (GetMessage (&msg, NULL, 0, 0))
  43.      {
  44.           TranslateMessage (&msg) ;
  45.           DispatchMessage (&msg) ;
  46.      }
  47.      return msg.wParam ;
  48. }

  49. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  50. {
  51.      HDC         hdc ;
  52.      PAINTSTRUCT ps ;
  53.      RECT        rect ;
  54.      
  55.      switch (message)
  56.      {
  57.      case WM_CREATE:
  58.           PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
  59.           return 0 ;
  60.          
  61.      case WM_PAINT:
  62.           hdc = BeginPaint (hwnd, &ps) ;
  63.          
  64.           GetClientRect (hwnd, &rect) ;
  65.          
  66.           DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
  67.                     DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
  68.          
  69.           EndPaint (hwnd, &ps) ;
  70.           return 0 ;
  71.          
  72.      case WM_DESTROY:
  73.           PostQuitMessage (0) ;
  74.           return 0 ;
  75.      }
  76.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  77. }
复制代码


2018-01-25_195219.jpg
最佳答案
2018-2-19 11:21:16
WndProc 函数中调用了PlaySound 函数,该函数依赖winmm.dll,你需要在项目设置中手动链接该函数库,或者使用#pragma comment()链接。

解决方法:
第二行添加  
#include <MMSystem.h>
#pragma comment(lib, "winmm.lib")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-2-19 11:21:16 | 显示全部楼层    本楼为最佳答案   
WndProc 函数中调用了PlaySound 函数,该函数依赖winmm.dll,你需要在项目设置中手动链接该函数库,或者使用#pragma comment()链接。

解决方法:
第二行添加  
#include <MMSystem.h>
#pragma comment(lib, "winmm.lib")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-25 08:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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