主题:一个封装MCI的LIB问题
jashon_w
[专家分:0] 发布于 2008-08-12 14:44:00
我准备把MCI的播放等控制,制作成一个LIB文件,可是在编译这个文件时,它始终需要stdafx.h,如果没有的话,就会报错如下:
Compiling...
WavReg.cpp
c:\program files\microsoft visual studio\vc98\include\vfw.h(67) : error C2146: syntax error : missing ';' before identifier 'FAR'
c:\program files\microsoft visual studio\vc98\include\vfw.h(67) : error C2501: 'DWORD' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\vfw.h(67) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
wavreg.lib - 3 error(s), 0 warning(s)
请教高手,不知道是什么原因?
下一贴贴上源代码:
回复列表 (共7个回复)
沙发
jashon_w [专家分:0] 发布于 2008-08-12 14:46:00
定义的类名:CWavReg
//头文件
#ifndef WAVREGH
#define WAVREGH
//#include "../stdafx.h"
//#include "windows.h"
#include "stdio.h"
#include "stdlib.h"
class CWaveReg
{
public:
CWaveReg();
CWaveReg(CString &str);
~CWaveReg();
HWND InitWav();
bool WavPlay();
bool WavSave();
bool WavStop();
bool WavRec();
bool WavPause();
HWND GetWavDev();
void SetFilename(CString &str);
private:
CString m_file;
HWND m_hMCIWnd;
};
#endif
板凳
jashon_w [专家分:0] 发布于 2008-08-12 14:47:00
//源文件
#include "stdafx.h"
#include <vfw.h>
#include <Mmsystem.h>
//#pragma comment(lib,"vfw32.lib")
//#pragma comment(lib,"Winmm.lib")
#include "wavreg.h"
CWaveReg::CWaveReg()
{
m_hMCIWnd=NULL;
}
CWaveReg::CWaveReg(CString &str)
{
m_hMCIWnd=MCIWndCreate(AfxGetMainWnd()->m_hWnd,
AfxGetInstanceHandle(),
//
// uncomment 'WS_VISIBLE' line to display the MCI window
//
// WS_VISIBLE |
WS_CHILD | WS_OVERLAPPED | WS_CAPTION | WS_BORDER |
MCIWNDF_RECORD | MCIWNDF_SHOWALL,
str);
m_file=str;
}
CWaveReg::~CWaveReg()
{
MCIWndClose(m_hMCIWnd);
MCIWndDestroy(m_hMCIWnd);
}
HWND CWaveReg::InitWav()
{
m_hMCIWnd=MCIWndCreate(AfxGetMainWnd()->m_hWnd,
AfxGetInstanceHandle(),
//
// uncomment 'WS_VISIBLE' line to display the MCI window
//
// WS_VISIBLE |
WS_CHILD | WS_OVERLAPPED | WS_CAPTION | WS_BORDER |
MCIWNDF_RECORD | MCIWNDF_SHOWALL,
NULL);
return m_hMCIWnd;
}
HWND CWaveReg::GetWavDev()
{
return m_hMCIWnd;
}
3 楼
jashon_w [专家分:0] 发布于 2008-08-12 14:47:00
void CWaveReg::SetFilename(CString &str)
{
m_file=str;
}
bool CWaveReg::WavPause()
{
bool ret=true;
long rr;
rr=MCIWndPause(m_hMCIWnd);
if (rr==0) ret=TRUE;
else ret=FALSE;
return ret;
}
bool CWaveReg::WavSave()
{
bool ret=true;
char file[260]="";
long rr;
sprintf(file,"aud%05d.wav",GetTickCount()%100000L); // random filename
if (!WavStop())
return FALSE;
if(MCIWndCanPlay(m_hMCIWnd)) //这里判断有没有可以播放的东西
{
rr=MCIWndSave(m_hMCIWnd,"a");
if (m_file.GetLength())
CopyFile("a",m_file,FALSE);
else
CopyFile("a",file,FALSE);
}
if (rr==0) ret=TRUE;
else ret=FALSE;
return ret;
}
bool CWaveReg::WavRec()
{
bool ret=true;
long rr;
MCIWndNew(m_hMCIWnd,"waveaudio");
// change the default audio setting (which is 11khz 8bit mono)
// to do this successfully, we need to change all of the following:
// MCI_WAVE_SET_PARMS members: wFormatTag, wBitsPerSample,
// nChannels, nSamplesPerSec, nAvgBytesPerSec, and nBlockAlign
MCI_WAVE_SET_PARMS set_parms;
set_parms.wFormatTag = WAVE_FORMAT_PCM;
set_parms.wBitsPerSample = 16;
set_parms.nChannels = 1;
set_parms.nBlockAlign = (set_parms.nChannels*set_parms.wBitsPerSample)/8;
set_parms.nSamplesPerSec = 44100;
set_parms.nAvgBytesPerSec = ((set_parms.wBitsPerSample) *
set_parms.nChannels *
set_parms.nSamplesPerSec)/8;
// now send the format changes with MCI_SET
int deviceID=MCIWndGetDeviceID(m_hMCIWnd);
int result = mciSendCommand( deviceID, MCI_SET,
MCI_WAIT
| MCI_WAVE_SET_FORMATTAG
| MCI_WAVE_SET_BITSPERSAMPLE
| MCI_WAVE_SET_CHANNELS
| MCI_WAVE_SET_SAMPLESPERSEC
| MCI_WAVE_SET_AVGBYTESPERSEC
| MCI_WAVE_SET_BLOCKALIGN,
(DWORD)(LPVOID)&set_parms);
if ( result ) // failed?
{
char buffer[100];
mciGetErrorString(result, buffer, sizeof(buffer));
AfxMessageBox(buffer);
return FALSE;
}
rr=MCIWndRecord(m_hMCIWnd);
if (rr==0) ret=TRUE;
else ret=FALSE;
return ret;
}
bool CWaveReg::WavPlay()
{
bool ret=true;
long rr;
if(MCIWndCanPlay(m_hMCIWnd)) //这里判断有没有可以播放的东西
{
rr=MCIWndPlay(m_hMCIWnd);
}
if (rr==0) ret=TRUE;
else ret=FALSE;
return ret;
}
bool CWaveReg::WavStop()
{
bool ret=true;
long rr;
rr=MCIWndStop(m_hMCIWnd);
if (rr==0) ret=TRUE;
else ret=FALSE;
return ret;
}
4 楼
jashon_w [专家分:0] 发布于 2008-08-12 14:48:00
如果把这个单独添加到一个MFC程序里面,是可以用的。
我主要是想把具体的功能能够封装一下。所以。。。。。。
在线期待中。。。
5 楼
olivertang [专家分:60] 发布于 2008-08-13 11:41:00
好像你没有理解stdafx.h在VC++中起到的作用是什么.
Windows和MFC的include文件都非常大,即使有一个快速的处理程序,编译程序也要花费相当长的时间来完成工作。由于每个.CPP文件都包含相同的include文件,为每个.CPP文件都重复处理这些文件就显得很傻了。
为避免这种浪费,AppWizard和VisualC++编译程序一起进行工作
AppWizard建立了文件stdafx.h,该文件包含了所有当前工程文件需要的MFCinclude文件。
6 楼
jashon_w [专家分:0] 发布于 2008-08-14 10:27:00
兄台,现在就是把那个stdafx.h加上,也会报一样的错!
7 楼
f-wind [专家分:1240] 发布于 2008-08-14 17:08:00
你新建一个工程默认就有stdafx.h文件了,再把其它加上就好!
我来回复