MFC扩展DLL中调用Windows Media Player

来源:互联网 发布:手机数据恢复安全 编辑:程序博客网 时间:2024/04/30 05:27

在MFC应用程序中调用Windows Media Player很简单,使用CWMPPlayer4类的Create()函数直接创建就可以了。

但是在MFC扩展DLL中用同样的方法,却行不通 :=(  ,MS的东西就是复杂。

MSDN提供的方法: https://msdn.microsoft.com/en-us/library/windows/desktop/dd563023(v=vs.85).aspx

#include "wmp.h"#include <atlbase.h>#include <atlcom.h>#include <atlhost.h>#include <atlctl.h>

CAxWindowm_wndView;CComPtr<IWMPPlayer4>m_spWMPPlayer;

AtlAxWinInit();

bool CMainPanel::InitPlay(){CComPtr<IAxWinHostWindow>  spHost;HRESULT  hr;RECT rect;GetClientRect(&rect);if(NULL == m_wndView.Create(GetSafeHwnd(), rect, NULL, WS_CHILD|WS_VISIBLE)){return false;}hr = m_wndView.QueryHost(&spHost);if(!SUCCEEDED(hr)){return false;}hr = spHost->CreateControl(CComBSTR(_T("{6BF52A52-394A-11d3-B153-00C04F79FAA6}")), m_wndView, 0);if(!SUCCEEDED(hr)){return false;}hr = m_wndView.QueryControl(&m_spWMPPlayer);if(!SUCCEEDED(hr)){return false;}return true;}

记得把项目的“ATL的使用”设置成“动态链接到ATL”,不然QueryHost的时候就会失败。这里搞了我很久!!