473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[C++/CLI] Callback from unmanaged to managed

Hi,

I did spend quite a long time finding how to call managed code from
unmanaged C++ class.
Here is the my final code:
http://xtware.com/mcallback/mcallback.htm

Is it the best way to do it?
Does
mgt^ callback = (mgt^)GCHandle::FromIntPtr(IntPtr(m_callback)).Tar get;
take long time to execute?

Can we do it a better way?

Remi

ps: I'll publish optimal solution in codeproject, there is so many people
having this question!

Mar 28 '06 #1
3 1968
I don't get the point, nothing in this sample is unmanaged code, everything
gets compiled to IL.
What you are doing can just be done like this:

class umgt
{
public:

void MyTreatment(mgt ^obj)
{
MyParameter ^param = gcnew MyParameter;
param->m_value = 123;
obj->MyCallback(param);
}
};

So I don't think this illustrates how to callback from unmanaged to managed.

Willy.
"Remi THOMAS [MVP]" <is*****@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
| Hi,
|
| I did spend quite a long time finding how to call managed code from
| unmanaged C++ class.
| Here is the my final code:
| http://xtware.com/mcallback/mcallback.htm
|
| Is it the best way to do it?
| Does
| mgt^ callback = (mgt^)GCHandle::FromIntPtr(IntPtr(m_callback)).Tar get;
| take long time to execute?
|
| Can we do it a better way?
|
| Remi
|
| ps: I'll publish optimal solution in codeproject, there is so many people
| having this question!
|
Mar 28 '06 #2
Hi Remi!
I did spend quite a long time finding how to call managed code from
unmanaged C++ class.
Here is the my final code:
http://xtware.com/mcallback/mcallback.htm

Is it the best way to do it?


The easiest Solution is to use the "gcroot" template...
This is exactly designed for your purpose...
See:
http://groups.google.de/group/micros...22b5a25?hl=de&

By the way:
Unmanaged in this context means: The class in not handled by the GC.
Unmanaged does not mean "native"...

Greetings
Jochen
Mar 28 '06 #3
"Remi THOMAS [MVP]" wrote
Hi,


Thanks for your answer.

I was sure gcroot disapear with C++/CLI. It's badly classify in MSDN I
think.

#pragma unmanaged
MSND says "An unmanaged function will be compiled for the native
platform...", confusing isn't it?

Remi

Mar 28 '06 #4

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

Similar topics

8
by: Nadav | last post by:
Hi, I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid...
2
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...
81
by: Don Kim | last post by:
I've been looking for a new IT position, and so far, the majority of work with respect to the Windows platform is C#/.Net, with some vb.net requests every so often. Even many of the C++/MFC/ATL...
1
by: stillh2os | last post by:
Hello. I'm new to .NET, and I'm trying to implement a callback function. I want my managed C++ code to call an unmanaged function, passing in a callback function that the unmanaged C/C++ code...
3
by: Cmtk Software | last post by:
I'm trying to define an enum which will be used from unmanaged c++, C++/CLI managed c++ and from C#. I defined the following enum in a VS dll project set to be compiled with the /clr switch: ...
12
by: DaTurk | last post by:
Hi, I have a rather interesting problem. I have a unmanged c++ class which needs to communicate information to managed c++ via callbacks, with a layer of c# on top of the managed c++ ultimatley...
5
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I have a class that is writen in unmanaged pure native C++. This class files (h and cpp) are inserted to a managed C++ (VC++ 2005, C++/CLI) DLL compoenet. This DLL compoenet is used in a C#...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
1
by: =?Utf-8?B?bGlnaHRkb2xs?= | last post by:
hello everyone. i have made a dll of c++/cli, then i want to exchange structure between c++/cli and c. this is the structure typedef struct tagExchange {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.