描述:
最近做东西遇到问题!!望高手指点!!
在网上看到一个类,放在自己机子上却不行:
以下是类的.h文件中的代码:
///////////////////////////////////////////////////////////////
// active speech engine
//
#include
extern CComModule _Module; //定义全局变量
#include
#include
#include
#include
///////////////////////////////////////////////////////////////
// speech message
//
#define WM_SREVENT WM_USER+102
class CSpeechRecognition
{
public:
CSpeechRecognition();
virtual ~CSpeechRecognition();
// initialize
BOOL Initialize(HWND hWnd = NULL, BOOL bIsShared = TRUE);
void Destroy();
// start and stop
BOOL Start();
BOOL Stop();
BOOL IsDictationOn ()
{
return m_bOnDictation;
}
// event handler事件句柄
void GetText(WCHAR **ppszCoMemText, ULONG ulStart = 0, ULONG nlCount = -1); //ULONG 64位数据类型
//WCHAR **指向16位指针的指针
// voice training语音训练
HRESULT VoiceTraining(HWND hWndParent);// hWndParent父句柄
//HRESULT存放返回值信息
// microphone setup麦克风安装
HRESULT MicrophoneSetup(HWND hWndParent);
// token list
HRESULT InitTokenList(HWND hWnd, BOOL bIsComboBox = FALSE);
// error string
CString GetErrorString()
{
return m_sError;
}
// interface CComPtr创建COM实例
CComPtr m_cpRecoEngine; // SR engine
CComPtr m_cpRecoCtxt; //Recognition contextfor dictation
CComPtr m_cpDictationGrammar; // Dictation grammar
private:
CString m_sError;
BOOL m_bOnDictation;
};
编译后提示了4个错误!不过是2个一样的.也就是有2个错误.
speechrecognition1.h(17) : error C2146: syntax error : missing ';' before identifier '_Module'
speechrecognition1.h(17) : fatal error C1004: unexpected end of file found
语音识别Dlg.cpp
speechrecognition1.h(17) : error C2146: syntax error : missing ';' before identifier '_Module'
speechrecognition1.h(17) : fatal error C1004: unexpected end of file found
解决方案1:
ATL中引入类模板是为了编程更容易,CComPtr是典型的类模板,需要接收参数:
比如:
CComPtr<IGoogleDesktopRegistrar> spRegistrar; //其中IGoogleDesktopRegistrar是接口
//创建spRegistrar类。其中类的私有数据是IGoogleDesktopRegistrar* 指针。
spRegistrar.CoCreateInstance(CLSID_GoogleDesktopRegistrar);//返回一个IGoogleDesktopRegistrar接口指针
那么以后就可以用spRegistrar->的方式使用接口的方法了。
CComModule的定义在atlbase.h文件中,要用的话要在定义对象之前#include <atlbase.h>
解决方案3: 这个问题我以前也遇到过,问题出在extern CComModule _Module; //定义全局变量
可能你的框架和你找这个类所在工程的框架类别不同,
可以试着在用到_Module的地方用__super::替换