C语言读取wav文件的问题,请大侠,编译问题。
代码如下:#include <windows.h>#include <math.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("SineWave") ;
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 ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow ( szAppName, TEXT ("Wave 13061128 李新"),
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 ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClient, cyClient ;
HDC hdc ;
PAINTSTRUCT ps ;
static int i=1;
TEXTMETRIC tm ;
static WORD Channels; //声道数目,1--单声道;2--双声道
static DWORD SamplesPerSec ;//采样频率
static WORD wBitsPerSample; //每个采样需要的bit数
static DWORD dwDataSize; //去除ID和Size所占的字节数后剩下的其他字节数目
static long size;
static int numbit;//一个样本的字节数;
static int num;//样本数
static BYTE *pData;
switch (message)
{
case WM_CREATE:
static HMMIO file1;//定义HMMIO文件句柄;
file1=mmioOpen("13061128.wav",NULL,MMIO_READWRITE);//以读写模式打开所给的WAVE文件;
if(file1==NULL)
{
MessageBox(hwnd,"WAVE文件打开失败!","13061128",0);
return NULL;
}
char style[3];
while(mmioSeek(file1,i++,SEEK_SET)&&i<200)
{
mmioRead(file1,style,3);
if(style[0]=='f'&&style[1]=='m'&&style[2]=='t')
break;
}
//////////////////////////////
mmioSeek(file1,i+9,SEEK_SET);
mmioRead(file1,style,2);
memcpy(&Channels,style,2);//声道
if(Channels==1)
MessageBox(hwnd,"单声道","13061128",0);
if(Channels==2)
MessageBox(hwnd,"双声道","13061128",0);
/////////////////////////
mmioSeek(file1,i+11,SEEK_SET);
mmioRead(file1,style,4);
memcpy(&SamplesPerSec,style,4);//采样频率
////////////////////////
mmioSeek(file1,i+21,SEEK_SET);
mmioRead(file1,style,2);
memcpy(&wBitsPerSample,style,2);//每个采样需要的bit数
if(wBitsPerSample==8)
MessageBox(hwnd,"8位量化","13061128",0);/////////
if(wBitsPerSample==16)
MessageBox(hwnd,"16位量化","13061128",0);
////////////////////////////
char style2[4];
while(mmioSeek(file1,i++,SEEK_SET)&&i<500)
{
mmioRead(file1,style2,4);
if(style2[0]=='d'&&style2[1]=='a'&&style2[2]=='t'&&style2[3]=='a')
{
// MessageBox(hwnd,"data","13061128",0);
break;
}
}
////////////////
mmioSeek(file1,i+3,SEEK_SET);
mmioRead(file1,(char*)&size,4);
// if(size%560256==0)
// MessageBox(hwnd,"qwwqeweq","46ty",0);
/////////////////////
i=i+7;
numbit=(wBitsPerSample/8);//一个样本的字节数;
num=size/numbit;//样本数
// if(560256==num)
// MessageBox(hwnd,"qwwqeweq","46ty",0);
pData=(BYTE*)new char[size];//
mmioSeek(file1,i,SEEK_SET);//对文件重新定位;
mmioRead(file1,(char*)pData,size);//
ReleaseDC (hwnd, hdc) ;
return 0 ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
if(Channels==1)
{
if(wBitsPerSample==8)
{
for(int k=0;k<size;k=k+size/50)//调节这里控制播放
{
for(int j=0;j<size;j++)
{
SetPixel(hdc,j-k,(WORD)*(pData+j),0) ;
}
PatBlt(hdc,0,0,50000,50000,WHITENESS);
}
MessageBox(hwnd,"播放完毕","13061128",0);
}
if(wBitsPerSample==16)
{
for(int k=0;k<size/2;k=k+size/100)//调节这里控制播放
{
for(int j=0;j<size/2;j++)
{
SetPixel(hdc,j-k,(WORD)*(pData+j*2),0) ;
}
PatBlt(hdc,0,0,50000,50000,WHITENESS);
}
MessageBox(hwnd,"播放完毕","13061128",0);
}
}
else if(Channels==2)
{
if(wBitsPerSample==8)
{
for(int k=0;k<size/2;k=k+size/100)//调节这里控制播放
{
for(int j=0;j<size/2;j++)
{
SetPixel(hdc,j-k,(WORD)*(pData+j*2),0) ;
}
for(j=0;j<size/2;j++)
{
SetPixel(hdc,j-k,(WORD)*(pData+1+j*2)+100,0) ;
}
PatBlt(hdc,0,0,50000,50000,WHITENESS);
}
MessageBox(hwnd,"播放完毕","13061128",0);
}
if(wBitsPerSample==16)
{
for(int k=0;k<size/4;k=k+size/200)//调节这里控制播放
{
for(int j=0;j<size/4;j++)
{
WORD w;
memcpy(&w,pData+j*4,2);
// SetPixel(hdc,j-k,w%1000-400,0) ;
SetPixel(hdc,j-k,w/50+100,0) ;
}
for(j=0;j<size/4;j++)
{
WORD w;
memcpy(&w,pData+2+j*4,2);
// SetPixel(hdc,j-k,w%1000-200,0) ;
SetPixel(hdc,j-k,w/50+350,0) ;
}
PatBlt(hdc,0,0,50000,50000,WHITENESS);
}
MessageBox(hwnd,"播放完毕","13061128",0);
}
}
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
问题:编译时过不了啊。VC6.0编译器。
Linking...
wav.obj : error LNK2001: unresolved external symbol __imp__mmioRead@12
wav.obj : error LNK2001: unresolved external symbol __imp__mmioSeek@12
wav.obj : error LNK2001: unresolved external symbol __imp__mmioOpenA@12
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/wav.exe : fatal error LNK1120: 4 unresolved externals
执行 link.exe 时出错.