in my project I have a "noncreatable" object.
The IDL (simplified) is the following:
[
object,
uuid(AB566C6D-AF54-11DE-B5BE-00A0D15E9B20),
oleautomation,
nonextensible,
helpstring("InterfaceA Interface"),
pointer_default(unique)
]
interface IAudioMixer : IUnknown
{
[propput, id(1)]
HRESULT PropertyA([in] short arg);
[propget, id(1)]
HRESULT PropertyA([out, retval] short* pVal);
};
//--------------------------------------------------
[
uuid(AB566C6F-AF54-11DE-B5BE-00A0D15E9B20),
dual,
nonextensible
]
interface IAudioPlayer : IDispatch
{
[propget, id(3), helpstring("Returns a reference to a IAudioMixer
interface.")]
HRESULT GetMixer([out, retval] IAudioMixer** pVal);
};
//--------------------------------------------------
[
uuid(AB566C66-AF54-11DE-B5BE-00A0D15E9B20),
version(1.0),
helpstring("....")
]
library MyLibrary
{
importlib("stdole2.tlb");
[
uuid(AB566C72-AF54-11DE-B5BE-00A0D15E9B20),
helpstring("AudioPlayer Class")
]
coclass AudioPlayer
{
[default] interface IAudioPlayer;
};
[
uuid(AB566C80-AF54-11DE-B5BE-00A0D15E9B20),
noncreatable,
helpstring("AudioMixer Class")
]
coclass AudioMixer
{
[default] interface IAudioMixer;
};
}
Now, in the CAudioPlayer class I have a member:
CComPtr<IAudioMixer> mixer_;
and in the FinalConstruct I have to create the object:
CAudioMixer* p_mixer;
IAudioMixer* i_mixer;
HRESULT hr = CComCoClass<CAudioMixer>::CreateInstance(&i_mixer);
if (SUCCEEDED(hr))
{
p_mixer = dynamic_cast<CAudioMixer*>(i_mixer);
p_mixer->SetMixerObj( player_->getAudioMixer() );
mixer_.Attach(i_mixer);
}
I coded in this way because CAudioMixer::SetMixerObject is not part of
the IAudioMixer interface.
Is there a better way to do the same job?
Thanks,
Daniele.
> Now, in the CAudioPlayer class I have a member:
>
> CComPtr<IAudioMixer> mixer_;
>
> and in the FinalConstruct I have to create the object:
>
> CAudioMixer* p_mixer;
> IAudioMixer* i_mixer;
>
> HRESULT hr = CComCoClass<CAudioMixer>::CreateInstance(&i_mixer);
>
> if (SUCCEEDED(hr))
> {
> p_mixer = dynamic_cast<CAudioMixer*>(i_mixer);
> p_mixer->SetMixerObj( player_->getAudioMixer() );
> mixer_.Attach(i_mixer);
> }
>
> I coded in this way because CAudioMixer::SetMixerObject is not part of
> the IAudioMixer interface.
> Is there a better way to do the same job?
"Better" depends on your taste, I guess ;-)
I do it like this:
CComObject<CAudioMixer> *pMixer = NULL;
hr = pMixer->CreateInstance(&pMixer);
if(SUCCEEDED(hr) && pMixer)
{
pMixer->SetMixerObj(player_->getAudioMixer());
hr = pMixer->QueryInterface(&mixer_);
}
if(pMixer && !mixer_)
delete pMixer;
pMixer = NULL;
// now use mixer_ if it is not NULL
--
SvenC
Yes, of course....
I'm not an expert in ATL and I asked only to know if there was some
"standard way" :-)
> I do it like this:
> CComObject<CAudioMixer> *pMixer = NULL;
> hr = pMixer->CreateInstance(&pMixer);
> if(SUCCEEDED(hr) && pMixer)
> {
> pMixer->SetMixerObj(player_->getAudioMixer());
> hr = pMixer->QueryInterface(&mixer_);}
>
> if(pMixer && !mixer_)
> delete pMixer;
> pMixer = NULL;
>
Thanks for your suggestion Sven!
Cheers,
Daniele.
You're welcome,
SvenC