473,499 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.

Oct 3 '07 #1
2 5173
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).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Doe" <jo**@doe.comwrote in message
news:5A**********************************@microsof t.com...
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.

Oct 3 '07 #2
you can fire some events in C++/CLI and handle these events in C#

--
Sheng Jiang
Microsoft MVP in VC++
"John Doe" <jo**@doe.comwrote in message
news:5A**********************************@microsof t.com...
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.

Oct 3 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2281
by: Melissa Wallis | last post by:
I have a class with 5 callbacks. Two of the callbacks work fine but the others don't. The main difference is that the callbacks that don't work are composed of a sequence of structs. I noticed a...
1
3369
by: Marwan | last post by:
Hello I am using asynchronous delegates to make a call to a COM ActiveX object, but even though the call occurs on a separate thread, my UI is still blocking. If i put the thread to sleep in my...
0
2703
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
5
3232
by: Christopher Jastram | last post by:
I'm a self-taught programmer, so this might be a pretty dumb question. If it is, please point me in the right direction and I shall apologize profusely. I have a question regarding C++ and...
2
2910
by: R. van der Welle | last post by:
Hi All, I am upgrading my app (working well with VB6) to VB.NET. It sends MIDI messages using the API multimedia winmm.dll . These functions are declared: Public Declare Function timeSetEvent...
0
1135
by: anilkoli | last post by:
I want clear cut idea about callbacks and also of delegates I have doughts about callbacks, I feel callbacks are used for 1. recursion 2. dynamically calling a perticular method out of many...
6
5099
by: HolyShea | last post by:
All, Not sure if this is possible or not - I've created a class which performs an asynchronous operation and provides notification when the operation is complete. I'd like the notification to be...
15
8367
by: dennis.richardson | last post by:
Greetings all. Here's a problem that's been driving me nuts for the last 48 hours. I'm hoping that someone has come across this before. I have a C# Application that reads a UDP broadcast...
5
2142
by: Simon | last post by:
I heard that we could do that by using AJAX. Could anybody share how to do it? Thanks.
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.