これが私のコードです:
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e)
{
System::Speech::Recognition::SpeechRecognizer ^sr = gcnew System::Speech::Recognition::SpeechRecognizer();
array<String ^> ^strs = gcnew array<String ^> {"Hello", "World"};
System::Speech::Recognition::Choices ^colors = gcnew System::Speech::Recognition::Choices();
colors->Add(strs);
System::Speech::Recognition::GrammarBuilder ^gb = gcnew System::Speech::Recognition::GrammarBuilder();
gb->Append(colors);
System::Speech::Recognition::Grammar ^g = gcnew System::Speech::Recognition::Grammar(gb);
sr->LoadGrammar(g);
// System::IntPtr ptr = gcnew System::IntPtr(&sr_SpeechRecognized);
sr->SpeechRecognized += gcnew System::EventHandler<System::Speech::Recognition::SpeechRecognizedEventArgs>(this,&Form1::sr_SpeechRecognized);
}
void sr_SpeechRecognized(System::Object ^sender, System::Speech::Recognition::SpeechRecognizedEventArgs^ e)
{
}
このコードは次のエラーを生成します
1>------ Build started: Project: SpeechTest, Configuration: Debug Win32 ------
1> SpeechTest.cpp
1>c:\users\yohan\documents\visual studio 2010\projects\speechtest\speechtest\Form1.h(144): error C3225: generic type argument for 'TEventArgs' cannot be 'System::Speech::Recognition::SpeechRecognizedEventArgs', it must be a value type or a handle to a reference type
1>c:\users\yohan\documents\visual studio 2010\projects\speechtest\speechtest\Form1.h(144): error C3352: 'void SpeechTest::Form1::sr_SpeechRecognized(System::Object ^,System::Speech::Recognition::SpeechRecognizedEventArgs ^)' : the specified function does not match the delegate type 'void (System::Object ^,System::Speech::Recognition::SpeechRecognizedEventArgs)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
ここでは、ハンドラーの作成を期待して、すべてが正常に機能しますsr->SpeechRecognized += gcnew System::EventHandler<System::Speech::Recognition::SpeechRecognizedEventArgs>(this,&Form1::sr_SpeechRecognized);
このハンドラ部分をコメントアウトすればOKです。ここで、Form
は現在の GUI フォーム、つまり C++/CLI によって構築されたデフォルトの GUI フォームを意味します。これらのコードはすべてそのフォーム内にあります。記事で読んだ方法でこのハンドラーを作成しました。次に何を試すことができますか?