我最近遇到了 COM inproc 服务器的问题。
我有一个实现接口的MCanvasFont
COM 对象:ICanvasFont
ICanvasFont : public IUnknown
{
virtual HRESULT STDMETHODCALLTYPE Create(
/* [in] */ BSTR bstrFamily,
/* [in] */ double fSize) = 0;
virtual HRESULT STDMETHODCALLTYPE SetSize(
/* [retval][out] */ double fSize) = 0;
};
这些MCanvasFont
对象持有一个不透明的指针,指向一个FontDelegate
实现实际字体操作的对象:
class MCanvasFont : public ICanvasFont
{
public:
MCanvasFont();
virtual ~MCanvasFont();
virtual HRESULT STDMETHODCALLTYPE QueryInterface(const IID& iid, void** ppv);
virtual ULONG STDMETHODCALLTYPE AddRef();
virtual ULONG STDMETHODCALLTYPE Release();
virtual HRESULT STDMETHODCALLTYPE Create(
/* [in] */ BSTR bstrFamily,
/* [in] */ double fSize);
virtual HRESULT STDMETHODCALLTYPE SetSize(
/* [in] */ double fSize);
protected:
class FontDelegate;
const std::unique_ptr<FontDelegate> m_font; // opaque pointer
// Reference count
long m_cRef;
};
还有一个MCanvas
实现ICanvas
接口的类。该ICanvas
接口具有SetFont(ICanvasFont* pFont)
设置当前字体的抽象方法和DrawText
在画布上绘制文本的方法:
class MCanvas : public ICanvas
{
public:
MCanvas();
virtual ~MCanvas();
virtual HRESULT STDMETHODCALLTYPE QueryInterface(const IID& iid, void** ppv);
virtual ULONG STDMETHODCALLTYPE AddRef();
virtual ULONG STDMETHODCALLTYPE Release();
STDMETHODDECL GetFont(
/* [retval][out] */ ICanvasFont** ppFont);
STDMETHODDECL SetFont(
/* [in] */ ICanvasFont* pFont);
// ...
STDMETHODDECL DrawText(
/* [in] */ double x,
/* [in] */ double y,
/* [in] */ BSTR text);
protected:
COMAutoPtr<ICanvasPen> m_pen;
COMAutoPtr<ICanvasBrush> m_brush;
COMAutoPtr<ICanvasFont> m_font;
// Reference count
long m_cRef;
};
我需要一种从方法访问FontDelegate
对象的MCanvas::DrawText
方法。最好的方法是什么?