#pragma once #include #include #include #include #include #include "ControlSite.h" #include "EventSink.h" // The XMMR control out of XMMT.ocx, which is what N1MM drives MMTTY and 2Tone // with. The control starts the engine, and the engine reports back through the // control's events. class XmmrControl { public: using EventHandler = SinkHandler; explicit XmmrControl(EventHandler handler) : handler_(std::move(handler)) {} ~XmmrControl() { destroy(); } bool create(HWND parent, std::string* error); void destroy(); HRESULT put(const wchar_t* name, VARIANT value); HRESULT putBool(const wchar_t* name, bool value); HRESULT putLong(const wchar_t* name, long value); HRESULT putString(const wchar_t* name, const std::string& value); HRESULT call(const wchar_t* name, VARIANT* arguments, unsigned count); HRESULT callLong(const wchar_t* name, long first, long second); long getLong(const wchar_t* name); std::string getString(const wchar_t* name); private: HRESULT invoke(const wchar_t* name, WORD flags, DISPPARAMS* arguments, VARIANT* result); bool listen(std::string* error); EventHandler handler_; ControlSite* site_ = nullptr; IOleObject* object_ = nullptr; IDispatch* dispatch_ = nullptr; IConnectionPoint* point_ = nullptr; IUnknown* sink_ = nullptr; DWORD cookie_ = 0; }; std::string toUtf8(const wchar_t* text); std::wstring toWide(const std::string& text);