Hi Tommy!
Ok, maybe MyClass is not native but it's unmanaged and it is the actual
definition of the class, which I can't change... it's inside a third party
dll. Anyhow, I have functions in a dll API that return objects of this type,
so how can I deal with it in for example C#?
I can't do like this, right?
In C#:
""""""
using MyWrapperNS; // Access to a MyWrapper type
using MyWrapperNSInternalNativeNS; //access to MyClass
You can´t access any unmanaged object (in a good way) from a managed
language.
So for your example it looks like the following:
<code>
#pragma unmanaged
class MyClass
{
public:
char* myStr;
CPoint myPoint;
int myInt;
CPoint getPoint() { return CPoint();}
};
#pragma managed
public __gc class MyClassWrapper : public IDisposable
{
public:
MyClassWrapper()
{
pMyClass = new MyClass();
}
__property System::String *get_MyStr()
{
if (pMyClass == NULL)
throw new System::InvalidOperationException(S"Object already
disposed!");
if (pMyClass->myStr == NULL)
return 0;
return new System::String(pMyClass->myStr);
}
__property int get_MyInt()
{
if (pMyClass == NULL)
throw new System::InvalidOperationException(S"Object already
disposed!");
return pMyClass->myInt;
}
__property System::Drawing::Point get_MyPoint()
{
if (pMyClass == NULL)
throw new System::InvalidOperationException(S"Object already
disposed!");
return System::Drawing::Point(pMyClass->myPoint.x,
pMyClass->myPoint.y);
}
System::Drawing::Point GetPoint()
{
if (pMyClass == NULL)
throw new System::InvalidOperationException(S"Object already
disposed!");
CPoint p = pMyClass->getPoint();
return System::Drawing::Point(p.x, p.y);
}
void Dispose()
{
Dispose(true);
}
private:
~MyClassWrapper()
{
Dispose(false);
}
void Dispose(bool disposing)
{
if (pMyClass != NULL)
delete pMyClass;
pMyClass = NULL;
if (disposing == true)
System::GC::SuppressFinalize(this);
}
MyClass *pMyClass;
};
</code>
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/