Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
let's say I have a class written in c++
C++
class Foo
{
 ...
 
 const Foo operator / (Foo& other_Foo)
{
  //internal calculus for division
  //returns new foo
}

 ...
}

and now I wrote a cli wrapper

C++
public ref class ManagedFoo
{
 ...

 ManagedFoo divide(ManagedFoo& other_ManagedFoo)
{
 //how do I call here the divide from the unmanaged???
}

 ...
}
Posted
Comments
Sergey Alexandrovich Kryukov 16-Mar-12 11:50am    
Yes, it could be a problem, but you did not explain enough, just the basic idea. You don't need to "divide from the unmanaged" (what is it?), you probably need to re-use unmanaged code in the managed implementation. How do you want it? Before coming to division, you need to define wrapping procedure: for example, you construct an unmanaged instance from the managed, then perform deletion, than construct the managed from unmanaged and return it. What are the problems you face down the road?

Also, think about it: why not simply implementing everything as managed code? The overhead of going between the manages and unmanages back and forth may or may not pay off...

In short, it's pretty difficult to see how to help you without more detailed description on your part.
--SA
m0rTu 18-Mar-12 19:31pm    
well I already have a managed wrapper for a unmanaged c++ written dll...I need to acces that division from inside the dll from within CLI because rewriting thousands of lines of code...not to mention bug free code tested for years is just not possible...
I am just wondering if having two unmanaged instances of a class and applying division "\" would call that unmanaged code...
Sergey Alexandrovich Kryukov 18-Mar-12 20:53pm    
Yes, it could, but as I described: make unmanaged from two managed operands, perform the binary operation, make managed from unmanaged result and return it. How you do the detail depends on what you already have. Do you have 1) a managed wrapper around unmanaged type, 2) umnaganged wrapper around managed type (???), 3) something else, 4) nothing?..
I would suggest you had a managed wrapper of the unmanaged type, had access to the unmanaged instance internally only and do like a just suggested.
--SA
m0rTu 19-Mar-12 4:54am    
I have the 1st option a managed wrapper around unmanaged type...I'll try today your proposal
Sergey Alexandrovich Kryukov 19-Mar-12 12:31pm    
Good. In this wrapper, you should have access to an unmanaged instance, but make sure it is internal (not public). You should also have an internal constructor which makes a wrapper instance out of the unmanaged instance. This is enough to write the numeric operation method.
--SA

1 solution

Well I found a solution...rather straightforward...some sort of copy constructor.
C++
ManagedFoo(ManagedFoo% other_ManagedFoo):Foo_point(other_ManagedFoo.get_native()){}

thats because If I have 2 managed foo instances I want to get the third by calling:
C++
ManagedFoo one( /*...*/ );
ManagedFoo two( /*...*/ );
ManagedFoo three = one.divide(two);


this is the code for the divide implementation:

C++
ManagedFoo ManagedFoo::divide(ManagedFoo %other_ManagedFoo)
{
	Foo res = Foo_point->operator/ (*(other_ManagedFoo.get_native())); 
	ManagedFoo result(new Foo(res));
	return result;
}

You can tell that .get_native() returns the pointer of the native instance.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900