Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

How to call C# callbacks from C++/CLI?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Doe - 03 Oct 2007 18:57 GMT
Hi,
   Tried searching Google on this topic but not many came up.  Basically I
have a C# GUI client that wants to receive 'notifications' from a worker DLL
(which is implemented in C++/CLI).  So far, from C# I am able to call any
method directly in C++/CLI DLL.  But I would like to have the C++/CLI invoke
some callback methods from within C# (some event notifications so that the
GUI updates its UI).
   In the old days using C/C++, I could do this easily by passing a class
object ptr to the DLL and have it invoke callback methods declared in that
class.  Can I do the same thing in .NET?  Since there is no header file, I
don't know how to 'tell' the C++/CLI component which C# callback methods to
use.  Thanks.
Sheng Jiang[MVP] - 03 Oct 2007 19:07 GMT
you can fire some events in C++/CLI and handle these events in C#

Signature

Sheng Jiang
Microsoft MVP in VC++

> Hi,
>     Tried searching Google on this topic but not many came up.  Basically I
[quoted text clipped - 8 lines]
> don't know how to 'tell' the C++/CLI component which C# callback methods to
> use.  Thanks.
Nicholas Paldino [.NET/C# MVP] - 03 Oct 2007 19:09 GMT
John,

   Basically, you would define a separate assembly where you define the
delegate that is used for the callback (or an interface, if you need a more
elaborate contract).

   Then, you would reference the callback from the client and in your C++
code, and expose the a parameter type/property/field which would receive the
callback in the C++ code.  Then, you can just execute the delegate when
needed (or the member on the interface, if that is the way you are going).

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi,
>    Tried searching Google on this topic but not many came up.  Basically I
[quoted text clipped - 8 lines]
> don't know how to 'tell' the C++/CLI component which C# callback methods
> to use.  Thanks.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.