问题
I am trying to write a program which captures your speech applies my effect on the captured audio and play it back immediately. I am writing this app to the windows store in c++. After suffering with MediaCapture I decided to use WASAPI to do that. I am using an example from the msdn to set up WASAPI. As I expected I ran into a problem very soon. So the problem is with the following two lines:
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
The visual studio says that:
Error: operand of __uuidof must have a class or enum type for which __declspec(uuid('..')) has been specified.
I haven't got any idea what it means. I would appreciate some help here.
回答1:
To be able to use __uuidof() a uuid must have been declared for the target. When compiling for Windows 8 Store Apps it seems that MMDeviceEnumerator and IMMDeviceEnumerator don't have any uuid declaration and you should instead use the Windows::Devices::Enumeration namespace to enumerate the devices and then use IActivateAudioInterfaceAsyncOperation to initialize and activate the audio device.
Here is a link to a fully working example that captures pcm data and writes it to a wav-file. It uses the systems' default audio capture device but enumerating the available devices and using any of them instead is a piece of cake. :)
WASAPI sample for Windows 8
来源:https://stackoverflow.com/questions/17493603/wasapi-windows-store-app-initialization