473,325 Members | 2,785 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,325 software developers and data experts.

Managed Wrapper with abstract classes

I am trying to create an managed wrapper but have some problems with it by
using abstract classes.

In my unmanaged library code i had the following three classes with the
following hierarchy

Referenced (class)
Object (abstract class, inheriting from referenced)
Node (class, inheriting from object)

I want to make an managed wrapper for it with the same type of classes. So i
created an managed referenced class, and because this is the base class i
give it the pointer to the unmanaged object referenced.

The object class will be an managed abstract class with no constructor,
because abstract class should not have one. One of the methods of the
unmanaged class is cloneObject which should be implemented by the classes
that are inheriting of the abstract class Node. CloneObject gives as result
an value of the type Object.

So now the problem, i create an managed class Node which implements the
cloneObject method. But how to define the body of this method. Because with
not abstract classes i have created an extra constructor which get the
unmanagedobject en wrapped it. But with an abstract return type this is not
possible.

Hope this gives you more details about my question, and i hope somebody had
an solution for it.

Thanx

WithPit

Nov 17 '05 #1
3 1770
Excuse me, but I couldn't understand the problem at all. It would be
better if you can provide a sample.

The abstract class can have a constructor, there is no restriction
about it. Interfaces and abstract classes are different, although they
have much in common. Abstract classes can contain data members, can
have virtual methods but those methods are required to be virtual.
However, abstract classes may contain one or more pure virtual methods,
which prevents you to instantiate the class. Therefore, instantiating
Node should be considered, rather than Object.

so,
__gc class Referenced
{

};

__abstract __gc class Obj
{
public:
Obj()
{
}
virtual Obj* cloneObject() = 0; // pure virtual
};

__gc class Node : public Obj
{
public:
virtual Obj* cloneObject()
{
Node* pnode = new Node;
// implementation (perhaps, copying)
return pnode;
}
};

should work fine

Nov 17 '05 #2
The problem is that the managed code is calling the unmanaged code. So for
the referenced class this means that it has an pointer to the unmanaged object

__gc class Referenced
{
unmanagedReferenced* _unmanagedObject;
};

with probaly a constructor, but that doesn't mater. The abstract class
object inheritance from Referenced. Like you say

__abstract __gc class Obj, public Referenced
{
public:
Obj()
{
}
virtual Obj* cloneObject() = 0; // pure virtual
};

And the Node class implements the method cloneObject().

__gc class Node : public Obj
{
public:
virtual Obj* cloneObject()
{
return new Obj(static_cast<unmanagedNode*>_unmanagedobject->cloneObject());
}
};

For this a constructor is needed with has an unmanaged object as argument.
That is not the problem. The point is that the unmanaged object is wrapped
inside the managed object but from the outside you don't know the type
anymore. You create a new Node object inside your example but maybe there are
methods when you don't know the exact return type. Could this not be a
problem for the managed wrapper? Or is this implementation the best? Or see i
things the wrong way.

Bye

WithPit

"ismailp" wrote:
Excuse me, but I couldn't understand the problem at all. It would be
better if you can provide a sample.

The abstract class can have a constructor, there is no restriction
about it. Interfaces and abstract classes are different, although they
have much in common. Abstract classes can contain data members, can
have virtual methods but those methods are required to be virtual.
However, abstract classes may contain one or more pure virtual methods,
which prevents you to instantiate the class. Therefore, instantiating
Node should be considered, rather than Object.

so,
__gc class Referenced
{

};

__abstract __gc class Obj
{
public:
Obj()
{
}
virtual Obj* cloneObject() = 0; // pure virtual
};

__gc class Node : public Obj
{
public:
virtual Obj* cloneObject()
{
Node* pnode = new Node;
// implementation (perhaps, copying)
return pnode;
}
};

should work fine

Nov 17 '05 #3
I forgot something, because with this implementation the Obj class cannot be
abstract because of the fact that it is now instantiated. I wanted to created
an managed wrapper with the same class structure so that abstract unmanaged
classes are also abstract in the managed wrapper and no objects could be
created of it.

You don't know wat type the unmanaged method returns, you only know the
abstract base type. So my question is, is there an implementation possible
with the use of abstract classes like Obj in this example?

Bye

WithPit

"WithPit" wrote:
The problem is that the managed code is calling the unmanaged code. So for
the referenced class this means that it has an pointer to the unmanaged object

__gc class Referenced
{
unmanagedReferenced* _unmanagedObject;
};

with probaly a constructor, but that doesn't mater. The abstract class
object inheritance from Referenced. Like you say

__abstract __gc class Obj, public Referenced
{
public:
Obj()
{
}
virtual Obj* cloneObject() = 0; // pure virtual
};

And the Node class implements the method cloneObject().

__gc class Node : public Obj
{
public:
virtual Obj* cloneObject()
{
return new Obj(static_cast<unmanagedNode*>_unmanagedobject->cloneObject());
}
};

For this a constructor is needed with has an unmanaged object as argument.
That is not the problem. The point is that the unmanaged object is wrapped
inside the managed object but from the outside you don't know the type
anymore. You create a new Node object inside your example but maybe there are
methods when you don't know the exact return type. Could this not be a
problem for the managed wrapper? Or is this implementation the best? Or see i
things the wrong way.

Bye

WithPit

"ismailp" wrote:
Excuse me, but I couldn't understand the problem at all. It would be
better if you can provide a sample.

The abstract class can have a constructor, there is no restriction
about it. Interfaces and abstract classes are different, although they
have much in common. Abstract classes can contain data members, can
have virtual methods but those methods are required to be virtual.
However, abstract classes may contain one or more pure virtual methods,
which prevents you to instantiate the class. Therefore, instantiating
Node should be considered, rather than Object.

so,
__gc class Referenced
{

};

__abstract __gc class Obj
{
public:
Obj()
{
}
virtual Obj* cloneObject() = 0; // pure virtual
};

__gc class Node : public Obj
{
public:
virtual Obj* cloneObject()
{
Node* pnode = new Node;
// implementation (perhaps, copying)
return pnode;
}
};

should work fine

Nov 17 '05 #4

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

Similar topics

4
by: 0to60 | last post by:
I'm trying to create a .dll with VS.NET 2003 Architect that contains a math computational component. I need the guts of the thing to be in native code, as performance is key for that part. But, I...
2
by: Paul Kenny | last post by:
Hi, I am trying to expose the functionality of an unmanaged C++ class to the other languages available in the .NET Framework. I have decided to do this by wrapping the unmanaged C++ class in a...
2
by: vidalsasoon | last post by:
I'm using a DLL that is a managed wrapper of a C++ dll. I have the source code to this wrapper. I think I found a bug so I want to snoop around the c++ code to see what is happening. In the...
10
by: E.T. Grey | last post by:
Hi, I have a C++ DLL that I want to use from a C# project. I am actually usng a lot of advanced C++ features like templates, partial/specialized templates, functors and callbacks. I am also...
9
by: WithPit | last post by:
I am trying to create an Managed C++ Wrapper around an unmanaged library which contains C++ code. Some of the unmanaged methods returns an returntype which is of the abstract base type (for...
1
by: c guan | last post by:
I have a simple Managed C++ wrapper built around an *existing* C++ interactive application. I can access the Managed C++ application classes from a VB .NET or C# client and the GUI part works as...
1
by: mschuck | last post by:
Here is the scenario I'm trying to make work. I've got 2 managed C++ classes, each of which wrappes an unmanaged C++ class, kind of like so: __nogc class UnmanagedClassA { public: void...
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...
1
by: thedbflow | last post by:
Folks, I have a bit of a quandary I was hoping for some expert guidance on. Keep in mind I am not a C++ developer, but I have worked with the language a bit. I have a native C++ API which I am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.