Hi WithPit!
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 example unmanagedObject). How can i convert this to the
managed abstract basetype?
If you really write an wrapper then your class should look like:
public __gc Wrapper : public IDisposable
{
public:
Wrapper() {pNative = new NativeClass
int WrapperFunction1(...) {return pNative->Function1(...);}
void WrapperFunction2(...) {return pNative->Function2(...);}
void Dispose() (delete pNative
;
private:
NativeClass *pNative;
};
(Of course, sometimes you need to do some marshalling...)
And now, if it returns the object itself, you just need to create an new
instance of the Wrapper-class (and you also must be sure to call the
correctly deletefuntion):
public __gc Wrapper : public IDisposable
{
public:
Wrapper() {pNative = new NativeClass
int WrapperFunction1(...) {return pNative->Function1(...);}
void WrapperFunction2(...) {return pNative->Function2(...);}
void Dispose() (delete pNative
;
// *the following is important!*
Wrapper *Function3 {return new Wrapper(pNative->Function3());}
private:
// *the following is important!*
Wrapper(NativeClass *pRef) {pNative = pRef;}
NativeClass *pNative;
};
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/