Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Delegates in Managed C++

Delegates in Managed C++

Scheduled Pinned Locked Moved Managed C++/CLI
tutorialcsharpc++question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    C LaMorticella
    wrote on last edited by
    #1

    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?

    U 1 Reply Last reply
    0
    • C C LaMorticella

      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?

      U Offline
      U Offline
      User 929285
      wrote on last edited by
      #2

      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; }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups