class TMyProc : public TCppInterfacedObject<TThreadProcedure>
{
private:
String p1;
String p2;
public:
TMyProc(String V1, String V2): p1(V1), p2(V2) {};
virtual void __fastcall Invoke(void)
{
Application->MessageBoxW(p1.c_str(), p2.c_str());
}
}; TThread::Synchronize(TThread::CurrentThread, new TMyProc("A", "B"));
相对于DELPHI来说有些麻烦,只能通过构造函数传参数。TCppInterfacedObject的定义如下:
#if !defined(INTFOBJECT_IMPL_IUNKNOWN)
#define INTFOBJECT_IMPL_IUNKNOWN(BASE) \
ULONG __stdcall AddRef() { return BASE::_AddRef();} \
ULONG __stdcall Release(){ return BASE::_Release();} \
HRESULT __stdcall QueryInterface(REFIID iid, void** p){ return BASE::QueryInterface(iid, p);}
#endif template <typename INTF1, typename INTF2=IUnknown, typename INTF3=IInterface>
class TCppInterfacedObject: public TInterfacedObject,
public INTF1, public INTF2, public INTF3
{
protected:
typedef TCppInterfacedObject<INTF1, INTF2, INTF3> _COM_CLASS;
public:
INTFOBJECT_IMPL_IUNKNOWN(TInterfacedObject);
};