windows编程常见异常(1)playsound的异常

windows编程常见错误(1)playsound的错误
题目来自http://zhidao.baidu.com/link?url=BgmQYddgQ3nhe4fotyX-zusLuuMYxsL_zFd8zraGp9bjHBFopJXxYqwLhL_6N11y2v15wBAtdALqsxVxX7gEa_
/*-------------------------------------------------- 
hellwin.c-display "hellowinxp" in the screen 
---------------------------------------------------*/ 
#include "windows.h" 

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

int WINAPI WinMain( 
HINSTANCE hInstance, 
HINSTANCE hPrevInstance, 
LPSTR lpCmdLine, 
int nCmdShow 
) 
{ 
static TCHAR szAppName[]=TEXT("hello winxp"); 
HWND hwnd; 
MSG msg; 
WNDCLASS wndclass; 

wndclass.style =CS_HREDRAW|CS_VREDRAW; 
wndclass.lpfnWndProc =WndProc; 
wndclass.cbClsExtra =0; 
wndclass.cbWndExtra =0; 
wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH); 
wndclass.hCursor =LoadCursor(NULL,IDC_HAND); 
wndclass.hIcon =LoadIcon(NULL,IDI_APPLICATION); 
wndclass.hInstance =hInstance; 
wndclass.lpszClassName =szAppName; 
wndclass.lpszMenuName =NULL; 

if(!RegisterClass(&wndclass)) 
{ 
MessageBox(NULL,TEXT("windows NT required"),szAppName,MB_ICONERROR); 
return 0; 
} 
hwnd=CreateWindow( 
szAppName, 
TEXT("the hello winxp program"), 
WS_OVERLAPPEDWINDOW, 
CW_USEDEFAULT, 
CW_USEDEFAULT, 
CW_USEDEFAULT, 
CW_USEDEFAULT, 
NULL, 
NULL, 
hInstance, 
NULL); 
ShowWindow(hwnd,nCmdShow); 
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("c:\\hell.wav"),NULL,SND_FILENAME|SND_ASYNC); //这里有问题 
return 0; 
case WM_PAINT: 
hdc=BeginPaint(hwnd,&ps); 
GetClientRect(hwnd,&rect); 
DrawText(hdc,TEXT("hello winxp"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER); 
EndPaint(hwnd,&ps); 
return 0; 
case WM_DESTROY: 
PostQuitMessage(0); 
return 0; 
} 
return DefWindowProc(hwnd,message,wParam,lParam); 
} 

编译出现如此错误提示:1>hellowinxp.obj : error LNK2019: unresolved external symbol __imp__PlaySoundW@12 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 
1>D:\myprj\mszjk\hellowinxp\Debug\hellowinxp.exe : fatal error LNK1120: 1 unresolved externals 
最好能翻译下错误代码。
解释一下具体原因,拷贝的别来了。我试过几乎没用。
谢谢
是的,有效,但我想知道具体解释。
下面是我在百度上面找到的答案可信的。这是因为playsound是在winmm.lib当中,这个文件在Vc中,系统不会默认添加需要手动添加的。即采用
#pragma comment添加的。具体见:http://blog.csdn.net/zhouyelihua/article/details/12625631

#include "windows.h" 

在这后面添加一句这个:#pragma comment( lib,"winmm.lib")
试试看吧。

因为PlaySound的函数声明你能看见,但是定义是放在库文件中的,所以应该导入库文件,这样你的程序才能看到函数的定义而不仅仅是声明。