< >我在C++中有工作代码来打印当前在WMP中播放的媒体名称。这是一个简单的控制台应用程序(78行代码)。在</p>
<p>步骤:</p>
<p><strong>1)</strong>实现一个基本的COM对象,实现IUnknown、IOleClientSite、IServiceProvider和IWMPMoteMediaServices。使用ATL模板CComObjectRootEx,这很简单(你的里程数可能会有所不同)。唯一需要(简单)代码的方法是IServiceProvider::QueryService和IWMPMoteMediaServices::GetServiceType。所有其他方法都可能返回E\u NOTIMPL</p>
<p><strong>2)</strong>实例化“WMPlayer.OCX版“COM对象(在我的例子中,通过CoCreateInstance)</p>
<p><strong>3)</strong>通过QueryInterface从对象检索IOleObject接口指针</p>
<p><strong>4)</strong>从1中看到的类实例化一个对象(我使用CComObject<;>;::CreateInstance模板)</p>
<p><strong>5)</strong>使用您在3处获得的接口中的SetClientSite方法,传递一个指向OleClientSite实现的指针。在</p>
<p><strong>6)</strong>在SetClientSite调用期间,WMP将回调您:首先请求IServiceProvider接口指针,然后调用QueryService方法,请求IWMPRemoteMediaServices接口指针。返回IWMPRemoteMediaServices的实现,第三,将通过GetServiceType再次调用您。然后必须返回“Remote”。您现在已连接到WMP运行实例</p>
<p><strong>7)</strong>查询COM对象以获取IWMPMedia接口指针</p>
<p><strong>8)</strong>如果7)没有给出NULL,则读取IWMPMedia::name属性。在</p>
<p><strong>9)</strong>完成</p>
<p>以上所有这些都在VS2010/windows7上进行了测试,并运行了WMP(如果没有运行媒体播放器进程,则什么也不做)。在</p>
<p>我不知道你是否可以/想用Python实现COM接口和对象。如果您对我的C++代码感兴趣,请告诉我。您可以在C++ DLL中使用该代码,然后从Python调用它。在</p>