从本机C++;类为C++/CX参考类? 我正在编写一个C++ WiRT组件DLL,用于基于.NET的WRET应用程序。DLL定义一个SoundSample ref类,该类通过调用创建XAudio语音。CreateSourceVoice采用“IXAudio2VoiceCallback*pcCallback”参数来启用对各种音频事件的回调。现在,我正试图基于实现该回调。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); };

从本机C++;类为C++/CX参考类? 我正在编写一个C++ WiRT组件DLL,用于基于.NET的WRET应用程序。DLL定义一个SoundSample ref类,该类通过调用创建XAudio语音。CreateSourceVoice采用“IXAudio2VoiceCallback*pcCallback”参数来启用对各种音频事件的回调。现在,我正试图基于实现该回调。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); };,c++,windows-runtime,c++-cx,C++,Windows Runtime,C++ Cx,在我尝试找出如何从本机回调类的实例回调到父SoundSample对象之前,一切都很好。我想我可以将SoundSample类的实例传递给SoundCallback对象,但它似乎不允许我在本机类中声明ref class字段: SoundCallback.h(9): error C2143: syntax error : missing ';' before '^' SoundCallback.h(9): error C4430: missing type specifier - int assume

在我尝试找出如何从本机回调类的实例回调到父SoundSample对象之前,一切都很好。我想我可以将SoundSample类的实例传递给SoundCallback对象,但它似乎不允许我在本机类中声明ref class字段:

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++中实现回调,到目前为止我还没有找到合理的解决方案。做这件事的最佳/最简单的方法是什么?

解决了这个问题(多亏了)-问题不在于任何障碍阻碍了在基本类中使用ref类。C4430意味着SoundSample是一种无法识别的类型,它被Intellisense隐藏了,因为这似乎表明SoundSample是已知的。 需要添加的是SoundSample类型的声明,这一切都可以正常工作

我刚才补充说

namespace MyNamespace { ref class SoundSample; }
在SoundCallback类声明之前,然后SoundCallback类可以声明:

MyNamespace::SoundSample^ sample;

顺便说一句,如果你知道解决这个问题的方法,那会有帮助的。我现在在C++中生疏了,现在我脑海里唯一的事情就是让ReF类实例旋转一个线程/在线程池线程上运行,等待来自本地类的线程事件——用SETVEATE、RESETEVEGECT、WaitForSingleObject etc. Why之类的东西来标记C++ 11?我对C++ 11不太了解,但是我假设这是一个混合Windows 8 C++ +Cx和本地C++的问题,可能有一些C++ 11方面的问题……好吧,虽然我并不认为“可能”是标记一些东西的充分理由。有了这个推理,你可以用C++ +1Talk标记大多数C++帖子,抱歉。我想也许我只是在寻找一个广泛的观众。。。