#define STRICT
#include<windows.h>
#include<mmsystem.h>
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,int nCmdShow)
{
sndPlaySound("DING.wav",SND_LOOP); //为何会报错?
return 0;
}以上一篇教程中的代码,编译通过,但不能运行!请高手指教!

解决方案 »

  1.   

    sndPlaySound("DING.wav",SND_LOOP); 
    --指定DING.wav的绝对路径试试
      

  2.   

    The specified sound must fit in available physical memory and be playable by an installed waveform-audio device driver. If sndPlaySound does not find the sound in the current directory, the function searches for it using the standard directory-search order.GetLastError检查一下。估计是文件格式不对或是在当前目录下找不到此文件。
      

  3.   

    如果要播放加载进资源里面的要用到MAKEINTRESOURCE()参数为其ID
    sndPlaySound(MAKEINTRESOURCE(ID_XXX),SND_LOOP);
      

  4.   

    Linking...
    2Sound.obj : error LNK2001: unresolved external symbol __imp__sndPlaySoundA@8
    Debug/2Sound.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.2Sound.exe - 2 error(s), 0 warning(s)这是运行时的错误。我试过了,路径没问题。我觉得问题可能出在库的链接上。仅仅包含#include<mmsystem.h>够了吗?是不是还需要添加其他的库?
      

  5.   

    加上lib库文件
    #pragma comment(lib,winmm.lib);
      

  6.   

    i_noname(一觉睡到大天黑)和  oyljerry(【勇敢的心】→ ㊣回家≡赞√㊣)确实很厉害啊!非常感谢!同时也感谢其他朋友的相助!oyljerry(【勇敢的心】→ ㊣回家≡赞√㊣)的格式不太正确:以下格式可以正常工作啊:)
    #pragma comment(lib,"winmm")
    或者
    #pragma comment(lib,"winmm.lib")