Rainmeter现在在C#中播放

时间:2014-10-09 20:15:30

标签: c# c++ plugins dll rainmeter

是否可以在C#项目中使用Rainmeter的NowPlaying.dll(C ++),如果是这样的话?如果没有Rainmeter,可以使用.dll吗?我想从Windows Media Player获取当前歌曲的元数据。

这是一个头文件(PlayerWMP.h):

#define __PLAYERWMP_H__

#include "Player.h"
#include <wmp.h>
#include <wrl/client.h>

class PlayerWMP : public Player
{
public:
virtual ~PlayerWMP();

static Player* Create();

virtual void UpdateData();

virtual void Pause();
virtual void Play();
virtual void Stop();
virtual void Next();
virtual void Previous();
virtual void SetPosition(int position);
virtual void SetRating(int rating);
virtual void SetVolume(int volume);
virtual void OpenPlayer(std::wstring& path);
virtual void ClosePlayer();

protected:
PlayerWMP();

private:
class CRemoteHost :
    public IServiceProvider,
    public IWMPRemoteMediaServices,
    public IWMPEvents
{
public:
    CRemoteHost();
    ~CRemoteHost();

    PlayerWMP* m_Player;

    IUnknown* GetUnknown() const { return (IServiceProvider*)this; }

    // IUnknown
    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID uuid, void** object) override;
    virtual ULONG STDMETHODCALLTYPE AddRef() override;
    virtual ULONG STDMETHODCALLTYPE Release() override;

    // IServiceProvider
    STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void** ppv);

    // IWMPRemoteMediaServices
    STDMETHOD(GetServiceType)(BSTR* pbstrType);
    STDMETHOD(GetApplicationName)(BSTR* pbstrName);
    STDMETHOD(GetScriptableObject)(BSTR* pbstrName, IDispatch** ppDispatch);
    STDMETHOD(GetCustomUIMode)(BSTR* pbstrFile);

    // IWMPEvents
    void STDMETHODCALLTYPE OpenStateChange(long NewState) {}
    void STDMETHODCALLTYPE PlayStateChange(long NewState);
    void STDMETHODCALLTYPE AudioLanguageChange(long LangID) {}
    void STDMETHODCALLTYPE StatusChange() {}
    void STDMETHODCALLTYPE ScriptCommand(BSTR scType, BSTR Param) {}
    void STDMETHODCALLTYPE NewStream() {}
    void STDMETHODCALLTYPE Disconnect(long Result) {}
    void STDMETHODCALLTYPE Buffering(VARIANT_BOOL Start) {}
    void STDMETHODCALLTYPE Error() {}
    void STDMETHODCALLTYPE Warning(long WarningType, long Param, BSTR Description) {}
    void STDMETHODCALLTYPE EndOfStream(long Result) {}
    void STDMETHODCALLTYPE PositionChange(double oldPosition, double newPosition) {}
    void STDMETHODCALLTYPE MarkerHit(long MarkerNum) {}
    void STDMETHODCALLTYPE DurationUnitChange(long NewDurationUnit) {}
    void STDMETHODCALLTYPE CdromMediaChange(long CdromNum) {}
    void STDMETHODCALLTYPE PlaylistChange(IDispatch* Playlist, WMPPlaylistChangeEventType change) {}
    void STDMETHODCALLTYPE CurrentPlaylistChange(WMPPlaylistChangeEventType change) {}
    void STDMETHODCALLTYPE CurrentPlaylistItemAvailable(BSTR bstrItemName) {}
    void STDMETHODCALLTYPE MediaChange(IDispatch* pdispMedia) {}
    void STDMETHODCALLTYPE CurrentMediaItemAvailable(BSTR bstrItemName) {}
    void STDMETHODCALLTYPE CurrentItemChange(IDispatch* pdispMedia);
    void STDMETHODCALLTYPE MediaCollectionChange() {}
    void STDMETHODCALLTYPE MediaCollectionAttributeStringAdded(BSTR bstrAttribName,  BSTR bstrAttribVal) {}
    void STDMETHODCALLTYPE MediaCollectionAttributeStringRemoved(BSTR bstrAttribName,  BSTR bstrAttribVal) {}
    void STDMETHODCALLTYPE MediaCollectionAttributeStringChanged(BSTR bstrAttribName, BSTR bstrOldAttribVal, BSTR bstrNewAttribVal) {}
    void STDMETHODCALLTYPE PlaylistCollectionChange() {}
    void STDMETHODCALLTYPE PlaylistCollectionPlaylistAdded(BSTR bstrPlaylistName) {}
    void STDMETHODCALLTYPE PlaylistCollectionPlaylistRemoved(BSTR bstrPlaylistName) {}
    void STDMETHODCALLTYPE PlaylistCollectionPlaylistSetAsDeleted(BSTR bstrPlaylistName, VARIANT_BOOL varfIsDeleted) {}
    void STDMETHODCALLTYPE ModeChange(BSTR ModeName, VARIANT_BOOL NewValue) {}
    void STDMETHODCALLTYPE MediaError(IDispatch* pMediaObject) {}
    void STDMETHODCALLTYPE OpenPlaylistSwitch(IDispatch* pItem) {}
    void STDMETHODCALLTYPE DomainChange(BSTR strDomain) {}
    void STDMETHODCALLTYPE SwitchedToPlayerApplication() {}
    void STDMETHODCALLTYPE SwitchedToControl();
    void STDMETHODCALLTYPE PlayerDockedStateChange() {}
    void STDMETHODCALLTYPE PlayerReconnect() {}
    void STDMETHODCALLTYPE Click(short nButton, short nShiftState, long fX, long fY) {}
    void STDMETHODCALLTYPE DoubleClick(short nButton, short nShiftState, long fX, long fY) {}
    void STDMETHODCALLTYPE KeyDown(short nKeyCode, short nShiftState) {}
    void STDMETHODCALLTYPE KeyPress(short nKeyAscii) {}
    void STDMETHODCALLTYPE KeyUp(short nKeyCode, short nShiftState) {}
    void STDMETHODCALLTYPE MouseDown(short nButton, short nShiftState, long fX, long fY) {}
    void STDMETHODCALLTYPE MouseMove(short nButton, short nShiftState, long fX, long fY) {}
    void STDMETHODCALLTYPE MouseUp(short nButton, short nShiftState, long fX, long fY) {}

private: 
ULONG m_RefCount;
};

void Initialize();
void Uninitialize();

static Player* c_Player;

bool m_TrackChanged;
HWND m_Window;
DWORD m_LastCheckTime;

Microsoft::WRL::ComPtr<IWMPPlayer4> m_IPlayer;
Microsoft::WRL::ComPtr<IWMPControls> m_IControls;
Microsoft::WRL::ComPtr<IWMPSettings> m_ISettings;
Microsoft::WRL::ComPtr<IConnectionPoint> m_IConnectionPoint;
DWORD m_ConnectionCookie;
};

的问候, 菲利克斯

1 个答案:

答案 0 :(得分:0)

不幸的是,你不能直接从C#使用c ++类。如果你真的想要这个,你必须在Visual C ++中创建ref类,将它们包装在提到的头文件中。