473,386 Members | 1,679 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,386 software developers and data experts.

Unmanaged to managed callback, and GCHandle / gcroot

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
looking at this example from MSDN.

http://msdn2.microsoft.com/en-us/lib...e0(VS.80).aspx

They have two examples, one where the GCHandle has class scope, and
then another where it is static, and it's global.

My problem is that I need each CLI instance of this object to have
it's own GCHandle to it's own calback into the native world, will a
instance variable of GCHandle cover this?

Jul 18 '07 #1
7 6416

"DaTurk" <mm******@hotmail.comwrote in message
news:11**********************@e16g2000pri.googlegr oups.com...
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
looking at this example from MSDN.

http://msdn2.microsoft.com/en-us/lib...e0(VS.80).aspx

They have two examples, one where the GCHandle has class scope, and
then another where it is static, and it's global.

My problem is that I need each CLI instance of this object to have
it's own GCHandle to it's own calback into the native world, will a
instance variable of GCHandle cover this?
Just use gcroot instead of GCHandle, it takes care of all the details. You
can treat it like a T^ (tracking reference) except it's a member of a native
class instead of a managed class.
Jul 19 '07 #2
On Jul 19, 4:56 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"DaTurk" <mmagd...@hotmail.comwrote in message

news:11**********************@e16g2000pri.googlegr oups.com...


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
looking at this example from MSDN.
http://msdn2.microsoft.com/en-us/lib...e0(VS.80).aspx
They have two examples, one where the GCHandle has class scope, and
then another where it is static, and it's global.
My problem is that I need each CLI instance of this object to have
it's own GCHandle to it's own calback into the native world, will a
instance variable of GCHandle cover this?

Just use gcroot instead of GCHandle, it takes care of all the details. You
can treat it like a T^ (tracking reference) except it's a member of a native
class instead of a managed class.- Hide quoted text -

- Show quoted text -
I can't use gcroot, because I'm using this reference in a unmanaged
class i.e. #pragma unmanaged. And so it doesn't recognize the CLI
delegate reference.

Jul 24 '07 #3

"DaTurk" <mm******@hotmail.comwrote in message
news:11**********************@w3g2000hsg.googlegro ups.com...
On Jul 19, 4:56 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
>"DaTurk" <mmagd...@hotmail.comwrote in message

news:11**********************@e16g2000pri.googleg roups.com...


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
looking at this example from MSDN.
>http://msdn2.microsoft.com/en-us/lib...e0(VS.80).aspx
They have two examples, one where the GCHandle has class scope, and
then another where it is static, and it's global.
My problem is that I need each CLI instance of this object to have
it's own GCHandle to it's own calback into the native world, will a
instance variable of GCHandle cover this?

Just use gcroot instead of GCHandle, it takes care of all the details.
You
can treat it like a T^ (tracking reference) except it's a member of a
native
class instead of a managed class.- Hide quoted text -

- Show quoted text -

I can't use gcroot, because I'm using this reference in a unmanaged
class i.e. #pragma unmanaged. And so it doesn't recognize the CLI
delegate reference.
Your shim will have to be #pragma managed, native class I believe (not ref
class).
Jul 24 '07 #4
On Jul 24, 12:31 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"DaTurk" <mmagd...@hotmail.comwrote in message

news:11**********************@w3g2000hsg.googlegro ups.com...


On Jul 19, 4:56 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"DaTurk" <mmagd...@hotmail.comwrote in message
>news:11**********************@e16g2000pri.googleg roups.com...
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
looking at this example from MSDN.
http://msdn2.microsoft.com/en-us/lib...e0(VS.80).aspx
They have two examples, one where the GCHandle has class scope, and
then another where it is static, and it's global.
My problem is that I need each CLI instance of this object to have
it's own GCHandle to it's own calback into the native world, will a
instance variable of GCHandle cover this?
Just use gcroot instead of GCHandle, it takes care of all the details.
You
can treat it like a T^ (tracking reference) except it's a member of a
native
class instead of a managed class.- Hide quoted text -
- Show quoted text -
I can't use gcroot, because I'm using this reference in a unmanaged
class i.e. #pragma unmanaged. And so it doesn't recognize the CLI
delegate reference.

Your shim will have to be #pragma managed, native class I believe (not ref
class).- Hide quoted text -

- Show quoted text -
I can't though. IT has to be a pragma unmanaged, because the classes
are callback classes that get activated via a strait c++ third party
orb.

Jul 30 '07 #5

"DaTurk" <mm******@hotmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
On Jul 24, 12:31 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
>"DaTurk" <mmagd...@hotmail.comwrote in message

news:11**********************@w3g2000hsg.googlegr oups.com...


On Jul 19, 4:56 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"DaTurk" <mmagd...@hotmail.comwrote in message
>>news:11**********************@e16g2000pri.google groups.com...
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
looking at this example from MSDN.
>http://msdn2.microsoft.com/en-us/lib...e0(VS.80).aspx
They have two examples, one where the GCHandle has class scope, and
then another where it is static, and it's global.
My problem is that I need each CLI instance of this object to have
it's own GCHandle to it's own calback into the native world, will a
instance variable of GCHandle cover this?
>Just use gcroot instead of GCHandle, it takes care of all the details.
You
can treat it like a T^ (tracking reference) except it's a member of a
native
class instead of a managed class.- Hide quoted text -
>- Show quoted text -
I can't use gcroot, because I'm using this reference in a unmanaged
class i.e. #pragma unmanaged. And so it doesn't recognize the CLI
delegate reference.

Your shim will have to be #pragma managed, native class I believe (not
ref
class).- Hide quoted text -

- Show quoted text -

I can't though. IT has to be a pragma unmanaged, because the classes
are callback classes that get activated via a strait c++ third party
orb.
Does this third-party code generator create source code, or binaries? If
source code, no problem, compile with /clr and you can use unmanaged classes
all day. If binaries, then you have bigger problems than .NET
compatibility -- to wit, lockin to a particular compiler version and
particular compile options.
Aug 2 '07 #6
Um, I'm not entirely sure about code generation. We're talking about
CORBA here, all I know is I pass these "callback" c++ #pragma
unmanaged classes to the POA_MANAGER, and it "activates" them so that
I can use them to receive callbacks from the ORB. So, I'm not sure if
that explains it really. But because I'm plugging these classes into
a black box, third party, ORB magic thingy .... I'm reluctant to mix
too much tech.

Aug 6 '07 #7

"DaTurk" <mm******@hotmail.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
Um, I'm not entirely sure about code generation. We're talking about
CORBA here, all I know is I pass these "callback" c++ #pragma
unmanaged classes to the POA_MANAGER, and it "activates" them so that
I can use them to receive callbacks from the ORB. So, I'm not sure if
that explains it really. But because I'm plugging these classes into
a black box, third party, ORB magic thingy .... I'm reluctant to mix
too much tech.
What exactly do you give the manager? Source code? Binary interface
pointers?
Aug 6 '07 #8

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

Similar topics

2
by: Sasha Nikolic | last post by:
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...
3
by: Thorsten | last post by:
HI I'm a C# developer and unfortunately I have to write now some code in managed and unmanaged C++. In this area I'm Newbie and therefore please forgive me if this is a really simple...
13
by: bonk | last post by:
Hello, I am trying to create a dll that internally uses managed types but exposes a plain unmanaged interface. All the managed stuff shall be "wrapped out of sight". So that I would be able to...
8
by: Notre Poubelle | last post by:
Hello, I have some legacy unmanaged C++ code in which I've introduced some managed C++ using the new CLI feature of VS 2005. My managed C++ code invokes a number of methods on a new C#class...
6
by: Stephen Walch | last post by:
Our application environment consists of three basic layers: 1. Third-party unmanaged DLLs that were written before the CLR was invented and maintain a significant amount of information (including...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
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...
3
by: mclp | last post by:
Hi. Just joined this group and I don't think this had been addressed before.. I have a VB.NET class library assembly "xyz.dll" that I want to access from some unmanaged code in an MFC DLL...
9
by: =?Utf-8?B?RWR3YXJkUw==?= | last post by:
I would greatly appreciate some help on passing managed object into unmanaged code. I need to pass a reference (address of) of a managed class into unmanaged code (written by a thrid party). The...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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
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...

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.