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