Delegates in Managed C++
-
I am using Asynchronous calls to a remote object in managed C++. The client is also managed C++ and uses delegates with BeginInvoke and EndInvoke. I have this all working and compiling fine so long as the parameters to the romote object are all input parameters. I can not figure out how to specify the delegate/BeginInvoke/EndInvoke with an output parameter. Is there an equivalent to the C# ref or out ? Can anyone provide an example of how to do this?
-
I am using Asynchronous calls to a remote object in managed C++. The client is also managed C++ and uses delegates with BeginInvoke and EndInvoke. I have this all working and compiling fine so long as the parameters to the romote object are all input parameters. I can not figure out how to specify the delegate/BeginInvoke/EndInvoke with an output parameter. Is there an equivalent to the C# ref or out ? Can anyone provide an example of how to do this?
Here's a simple example:
#using using namespace System; public __delegate Int32 FactorialCallback(Int32,Int32*); public __gc class Factorial{ public: FactorialCallback *fc; Factorial(){ this->fc=new FactorialCallback(this, GetFactorial); } Int32 GetFactorial(Int32 iSeed, Int32 *iNumberOfCircles){ (*iNumberOfCircles)++; return (iSeed==0)?1:(GetFactorial(iSeed-1,iNumberOfCircles)*iSeed); } Void FactorialComplete(IAsyncResult *ar){ Int32 iNumberOfCircles; Int32 iResult=this->fc->EndInvoke(&iNumberOfCircles,ar); Console::WriteLine(S"The result is {0}, nuber of circles is {1}",iResult.ToString(),(iNumberOfCircles-1).ToString()); Console::Read(); } }; int _tmain() { Factorial *fact=new Factorial(); Int32 dummy=0; AsyncCallback *ac=new AsyncCallback(fact,&Factorial::FactorialComplete); fact->fc->BeginInvoke(5,&dummy,ac,NULL); Console::WriteLine(S"Main complete"); Console::Read(); return 0; }