IServiceProvider::QueryService returned E_INVALIDARG in mfc

335 views Asked by At

I am working on a small application. I want to embed the ActiveX Control and want to remote it in a mfc application. For I need a IServiceProvider Interface of COM. IServiceProvider gives the access of IWMPRemoteMediaAccess interface. For that I am using this:

But It returnes E_INVALIDARG every time. Can anyone tell me what could be the problem.

IOleObject* oleObject;
CComPtr<IServiceProvider>   m_spProvider;
CComPtr<IWMPRemoteMediaServices> m_spServices;

HRESULT hr = CoCreateInstance(__uuidof(WindowsMediaPlayer), 0, CLSCTX_INPROC_SERVER, IID_IOleObject, (void**)&oleObject);

hr = oleObject->QueryInterface(__uuidof(IServiceProvider), (void**)&m_spProvider);
if(SUCCEEDED(hr))
{
//Here It return E_INVALIDARG (hr = E_INVALID_ARG)
hr = m_spProvider->QueryService(__uuidof(IWMPRemoteMediaServices), IID_IServiceProvider,   (void**)&m_spServices);

}

I am not able to understand which argument is wrong. I more sure about first argument. can anyone tell me what it could be.

Thank You

1

There are 1 answers

5
Roman Ryltsov On

IWMPRemoteMediaServices is the interface you are supposed to implement on your side, not to query via QueryService. MSDN:

Enabling Remote Embedding

To enable remote embedding of the Windows Media Player control, your program must implement the IServiceProvider and IWMPRemoteMediaServices interfaces. IServiceProvider is a standard Component Object Model (COM) interface with a single method called QueryService. Windows Media Player calls this method to retrieve a pointer to an IWMPRemoteMediaServices interface.

Then WMP will call methods of this interface, methods that you implement. The code you are showing is an attempt to obtain WMP's IServiceProvider and services that the control implements. Vice versa, this is what WMP will do - it will discover services that you implement.

See RemoteHost.h and RemoteHost.cpp here on how your classes should look like.