gpt4 book ai didi

delphi - Delphi XE2中调用 "IAudioSessionManager2.GetSessionEnumerator()"时出现异常

转载 作者:行者123 更新时间:2023-12-03 15:48:37 27 4
gpt4 key购买 nike

下面的代码在 Delphi XE2 Win32 下编译并在 Win 7 64 位下运行,在执行“AudioSessionManager2.GetSessionEnumerator”行时产生以下异常:

“Project22.exe 引发异常类 $C0000005,并显示消息“0x7027edb2 处的访问冲突:写入地址 0x0051ced6””

我缺乏对异常类或其含义的了解,因此我不知道异常的含义或如何修复它。

这是引发异常的代码(用于调试代码的断言):

var
HRES: HRESULT;
DeviceEnumerator: IMMDeviceEnumerator;
DefaultDevice: IMMDevice;
AudioSessionManager2: IAudioSessionManager2;
Enumerator: IAudioSessionEnumerator;
begin

CoInitialize( nil );

HRES := CoCreateInstance( CLSID_MMDeviceEnumerator, nil, CLSCTX_ALL, IID_IMMDeviceEnumerator, DeviceEnumerator );
Assert( Succeeded( HRES ) );

HRES := DeviceEnumerator.GetDefaultAudioEndpoint( eRender, eMultimedia, DefaultDevice );
Assert( Succeeded( HRES ) );

HRES := DefaultDevice.Activate( IID_IAudioSessionManager2, CLSCTX_ALL, nil, IUnknown( AudioSessionManager2 ) );
Assert( Succeeded( HRES ) );

HRES := AudioSessionManager2.GetSessionEnumerator( Enumerator ); // <- EXCEPTION HERE
Assert( Succeeded( HRES ) );

[snip]

我正在使用 MFPack on Google Code 中的核心音频定义,IAudioSessionManager2 和 IAudioSessionEnumerator 接口(interface)如下所示:

IAudioSessionManager2 = interface(IUnknown)
['{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}']
function GetSessionEnumerator(out SessionEnum: IAudioSessionEnumerator): HResult; stdcall;
function RegisterSessionNotification(SessionNotification: IAudioSessionNotification): HResult; stdcall;
function UnregisterSessionNotification(SessionNotification: IAudioSessionNotification): HResult; stdcall;
function RegisterDuckNotification(const sessionID: LPCWSTR; const duckNotification: IAudioVolumeDuckNotification): HResult; stdcall;
function UnregisterDuckNotification(const duckNotification: IAudioVolumeDuckNotification): HResult; stdcall;
end;

IAudioSessionEnumerator = interface(IUnknown)
['{E2F5BB11-0570-40CA-ACDD-3AA01277DEE8}']
function GetCount(out SessionCount: integer): HResult; stdcall;
function GetSession(const SessionCount: integer; out Session: IAudioSessionControl): HResult; stdcall;
end;

我相信接口(interface)已正确定义,并且我还仔细检查了 GUID。

由于在 Visual Studio 2012(Win32 项目)下按照预期执行相同的指令序列,我怀疑问题出在我的代码(这里毫无疑问)、Core Audio 接口(interface)定义或 Delphi 中。在VS中运行的C++代码如下:

IMMDeviceEnumerator *DeviceEnumerator = NULL;
IMMDevice* DefaultDevice = NULL;
IAudioSessionManager2* AudioSessionManager = NULL;
IAudioSessionEnumerator* Enumerator = NULL;
HRESULT HR;

HR = CoCreateInstance( __uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&DeviceEnumerator );
HR = DeviceEnumerator->GetDefaultAudioEndpoint( eRender, eMultimedia, &DefaultDevice );
HR = DefaultDevice->Activate( __uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL,(void**)&AudioSessionManager );
HR = AudioSessionManager->GetSessionEnumerator( &Enumerator );

使用 C++ 代码,我可以正确检索 session 枚举器并使用 GetCount 等。

我花了无数个小时试图找出我的代码出了什么问题,但我仍然一无所知,因此任何帮助将不胜感激。

最佳答案

根据 MSDN,IAudioSessionManager2应该继承自IAudioSessionManager :

type
IAudioSessionManager2 = interface(IAudioSessionManager)
...

关于delphi - Delphi XE2中调用 "IAudioSessionManager2.GetSessionEnumerator()"时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12660480/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com