MFC扩展DLL中调用Windows Media Player

在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>

CAxWindow				m_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的时候就会失败。这里搞了我很久!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值