.NET ベースの WinRT アプリケーションで使用する C++ WinRT コンポーネント DLL を作成しています。DLL は、 IXAudio2::CreateSourceVoiceを呼び出して XAudio 音声を作成する SoundSample ref クラスを定義します。CreateSourceVoice は、"IXAudio2VoiceCallback *pCallback" パラメーターを使用して、さまざまなオーディオ イベントでのコールバックを有効にします。今、この記事に基づいてそのコールバックを実装しようとしています。XAudio は、次のように定義された SoundCallback クラスのメソッドにコールバックするだけです。
#pragma once
#include "xaudio2.h"
#include "pch.h"
class SoundCallback
: public IXAudio2VoiceCallback
{
private:
//SoundSample^ sample; //does not compile
public:
SoundCallback(void);
~SoundCallback(void);
//Called when the voice has just finished playing a contiguous audio stream.
void OnStreamEnd();
void OnVoiceProcessingPassEnd();
void OnVoiceProcessingPassStart(UINT32 SamplesRequired);
void OnBufferEnd(void * pBufferContext);
void OnBufferStart(void * pBufferContext);
void OnLoopEnd(void * pBufferContext);
void OnVoiceError(void * pBufferContext, HRESULT Error);
};
ネイティブ コールバック クラスのインスタンスから親の SoundSample オブジェクトにコールバックする方法を見つけようとするまでは、すべて問題ありません。SoundSample クラスのインスタンスを SoundCallback オブジェクトに渡すことができると考えていましたが、ネイティブ クラスで ref クラス フィールドを宣言することはできないようです。
SoundCallback.h(9): error C2143: syntax error : missing ';' before '^'
SoundCallback.h(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
SoundCallback.h(9): error C3699: '^' : cannot use this indirection on type 'int'
ネイティブ C++ でのコールバックの実装を振り返ってみましたが、これまで合理的な解決策を見つけることができませんでした。これを行うための最良/最も簡単な方法は何ですか?