(LIST1) //. MIDIデバイスの現在の状態定数 CRITICAL_SECTION MIDICriticalSection; int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { ... InitializeCriticalSection(&MIDICriticalSection); } int CPlayThrd::Run() { ... EnterCriticalSection(&MIDICriticalSection); { while (1) { //. サウンド再生ループ for (int j = 0; juVoice, pnote->uNote, pnote->uVelocity); } LeaveCriticalSection(&MIDICriticalSection); } } LeaveCriticalSection(&MIDICriticalSection); return CWinThread::Run(); } (LIST2) int CPlayThrd::Run() { while (1) { //. サウンド再生ループ for (int j = 0; juVoice, pnote->uNote, pnote->uVelocity); } LeaveCriticalSection(&MIDICriticalSection); } return CWinThread::Run(); } (LIST3) class CMainFrame : public CMDIFrameWnd { ... public: //. 楽譜ドキュメントを再生中はtrueにする BOOL bInPlay; //. フレームクラスで宣言する //. つまり,アプリケーション全体で有効. ... } // 再生ボタンメッセージ ハンドラ void CMainFrame::OnPlaybutton() { if (bInPlay) { //. Stop (再生を止める処理) bInPlay = false; } else { //. Play (再生を開始する処理) bInPlay = true; //. スレッドを起動する m_pPlayThrd = (CPlayThrd *) AfxBeginThread(RUNTIME_CLASS(CPlayThrd)); } } (LIST4) void CMusiqueView::OnViewList() { ... CMusiqueDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CTypedPtrList& noteList = pDoc->m_NoteList; POSITION pos = noteList.GetHeadPosition(); // .MusiObjList1を始めて使う前にチェックする ASSERT_VALID(MusiObjList1); //. これを追加するだけ!!! POSITION pos1 = MusiObjList1->GetHeadPosition(); while (pos != NULL) { ... (LIST5) #ifdef _DEBUG FILE *MusiLogFp; void OpenLog() { //. デバッグログファイルを開く MusiLogFp = fopen("debug\\Musilog.txt", "w") ; } void CloseLog() { fclose(MusiLogFp) ; } //. 型チェックを厳しくするために //. 省略記号 (...) を使って宣言した可変個の引数を使う関数より, //. 関数をオーバーロードする //. (という例.この場合,あんまり意味はないけどね) void LogOut(LPCTSTR fmt, int i1, int i2) { fprintf(MusiLogFp, fmt, i1, i2); } void LogOut(LPCTSTR fmt, int i, LPCTSTR s) { fprintf(MusiLogFp, fmt, i, s); } void LogOut(LPCTSTR fmt, LPCTSTR s) { fprintf(MusiLogFp, fmt, s); } #endif