473,796 Members | 2,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing a callback to the unmanaged class

I have one unmanaged and one managed class in the same vc++ project. Managed
object creates one instance of unmanaged class and needs to pass a callback
reference so that unmanaged class can periodically call the managed class's
method (without holding the reference to the managed object).

Can anybody please provide me with a short example or a basic idea?

Thanks a lot,
Sasha
Nov 17 '05 #1
2 1700
Hi Sasha Nikolic,
I have one unmanaged and one managed class in the same vc++ project.
Managed object creates one instance of unmanaged class and needs to
pass a callback reference so that unmanaged class can periodically
call the managed class's method (without holding the reference to the
managed object).


How should the unmanaged class know with managed object to call if you do
not want to store the reference in the unmanaged object?

TO stare an managed object-reference in unmanaged code, you can use the
gcroot template.

See: Consuming Unmanaged C++ Class Libraries from .NET Clients
http://www.codeguru.com/Cpp/Cpp/cpp_...cle.php/c6867/

See: 16.3 __gc Pointers in Unmanaged Classes
http://msdn.microsoft.com/library/de...l=/library/en-
us/vcmxspec/html/vcManagedExtens ionsSpec_16_3.a sp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #2
Thanks Jochen, codeguru example is excellent! I needed very similar
solution.
"Jochen Kalmbach" <no************ ********@holzma .de> wrote in message
news:Xn******** *************** **********@127. 0.0.1...
Hi Sasha Nikolic,
I have one unmanaged and one managed class in the same vc++ project.
Managed object creates one instance of unmanaged class and needs to
pass a callback reference so that unmanaged class can periodically
call the managed class's method (without holding the reference to the
managed object).


How should the unmanaged class know with managed object to call if you do
not want to store the reference in the unmanaged object?

TO stare an managed object-reference in unmanaged code, you can use the
gcroot template.

See: Consuming Unmanaged C++ Class Libraries from .NET Clients
http://www.codeguru.com/Cpp/Cpp/cpp_...cle.php/c6867/

See: 16.3 __gc Pointers in Unmanaged Classes
http://msdn.microsoft.com/library/de...l=/library/en-
us/vcmxspec/html/vcManagedExtens ionsSpec_16_3.a sp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Nov 17 '05 #3

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

Similar topics

0
1759
by: vijaya | last post by:
I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.The unmanaged dll fucntion is as follows **************************************** The Original Fucntion in the dll **************************************** int PBORCA_LibraryDirectory ( HPBORCA hORCASession, LPSTR lpszLibName, LPSTR lpszLibComments, int iCmntsBuffSize, PBORCA_LISTPROC pListProc, LPVOID pUserData );
0
1213
by: bob | last post by:
Hi all Currently porting an application to managed C++ Have managed to create working MDI form and child windows etc. Also added a callback from an unmanaged 'C' dll (ok that was strangely easy to do and it works). The callback simply creates a string form the callback char * data
2
1794
by: MR | last post by:
help! I have an unmanaged DLL that I do not have the source code, so i can't recompile or make changes. the DLL requires a callback function. I would like to implement the callback method in a managed class. The unmanaged DLL gets the address of the callback in a struct (someStruct below) that is passed as a parameter. I can't seem to figure out how to pass the "unmanaged" address of a managed method to be uses as a callback. I would...
5
3419
by: Maxwell | last post by:
Hello, Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project where I have a managed class reference in a unmanaged class...simple enough. To keep things short I am for the most part attempting to do what is this article by Nish: http://www.voidnish.com/articles/ShowArticle.aspx?code=cbwijw I have to hook up a unmanaged callback to a managed method using IJW NOT P\Invoke. So I am employing this "Thunk" or "Bridge" class...
0
2019
by: Haxan | last post by:
Hi, I have an unmanaged application that converts a function pointer to a delegate and then pass this as a parameter(delegate) to a managed function which then invokes it. Currently Im able to jump to this unmanaged function, but the values of the parameters inside this function Im seeing are not correct(they have some garbage values). //unmanaged class (C++ application)
12
11371
by: Haxan | last post by:
Hi, I have my main application class(unmanaged) that has a none static member function that I need to pass as a delegate to managed C# method. In one of the methods of this class(unmamanged), I am calling a managed C# method(I use gcnew to instantiate the managed class). One of the parameters of this C# method is a delegate. I need to pass the none static member function as a delegate(function pointer) as a parameter in the managed C#...
7
6438
by: DaTurk | last post by:
Hi, I'm coding up an application that has a native c++ layer, asynchronously calling callback in a CLI layer. We originally did this with static inline methods in the CLI layer, but this solution only works with singleton objects. So I have to explore other solutions. So beside pinning pointers, I've been looking at GCHandle. I was
0
1402
by: DavidT | last post by:
Hello, at first, exuse if the following question is simple to solve, but i normaly coding with C# and now have to use C++/CLI for one project. My Problem is that i have to use a native c++ sdk to read pictures from ip cameras. I get the native c++ decoder worked so far and now try to send callbacks from unmanaged to managed code, to signal wenn a picture is fully received. To get a first view on that area i implemented a little test...
1
4543
by: Kenneth Porter | last post by:
I have an unmanaged library that can accept an instance of an abstract class and call back into it. I'm writing a wrapper for this library. How do I wrap a managed callback in a class derived from the unmanaged class to pass to the library? I tried creating a managed class that carries an unmanaged callback class which calls back into the managed class, but I can't put a handle to the unmanaged class in the unmanaged class. (I get...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10242
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6800
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5453
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.