1

我刚刚告诉 Xcode 将所有内容编译为 Objective-C++,现在我在转换时遇到了错误。

void audioRouteChangeListenerCallback (
                                       void                      *aInUserData,
                                       AudioSessionPropertyID    aInPropertyID,
                                       UInt32                    aInPropertyValueSize,
                                       const void                *aInPropertyValue
                                       ) {

    // Ensure that this callback was invoked because of an audio route change
    if (aInPropertyID != kAudioSessionProperty_AudioRouteChange) return;

    // This callback, being outside the implementation block, needs a reference to the MixerHostAudio
    //   object, which it receives in the inUserData parameter. You provide this reference when
    //   registering this callback (see the call to AudioSessionAddPropertyListener).
    TJUSimpleSequencer *lAudioObject = (TJUSimpleSequencer *) aInUserData;

    // if application sound is not playing, there's nothing to do, so return.
    if (NO == lAudioObject.isPlaying) {

        NSLog (@"Audio route change while application audio is stopped.");
        return;

    } else {

        // Determine the specific type of audio route change that occurred.
        CFDictionaryRef routeChangeDictionary = aInPropertyValue; // !!! invalid conversion from 'const void*' to 'const __CFDictionary*'

        CFNumberRef routeChangeReasonRef =
        CFDictionaryGetValue (
                              routeChangeDictionary,
                              CFSTR (kAudioSession_AudioRouteChangeKey_Reason)
                              ); // !!! invalid conversion from 'const void*' to 'const __CFNumber*'

当我尝试使用static_cast<CFDictionaryRef>(aInPropertyValue)时,我什么也得不到。好像(这可能是真的)我没有正确使用它。

4

1 回答 1

1

使用常规的 C 类型转换?

CFDictionaryRef routeChangeDictionary = ( CFDictionaryRef )aInPropertyValue;

编辑0:

这个函数调用怎么样(如果你确定它是一个数字:)

CFNumberRef routeChangeReasonRef =
    ( CFNumberRef )CFDictionaryGetValue ( ...

编辑1:

然后看看The Definitive C++ Book Guide and List

于 2011-04-10T02:09:23.433 回答