T
Tommy Svensson \(InfoGrafix\)
I've been instructed to work againt a huge unmanaged C++ API from a C#
application.
Now, the only way, as I've understood it, is to go the Managed Extensions
for C++ way. This means I have to write a wrapper between unmanaged API and
my managed app.
Now on to the question:
If there's an unmanaged API class called X with a defined method
TypeA* foobar(TypeB* b, TypeC* c);
then how can my managed code (my c# app) deal with the problem of inputing
TypeB and TypeC since they are not known or compatible with managed code,
and how should my c# app deal with the TypeA* return type?
Is there a way to "use" the unmanaged types "as they are" in the managed
code (maybe by uisng the API include files?) or do I have to do something
like this in my wrapper:
TypeA, TypeB and TypeC consists only of a public int member for simplicity.
public __gc class wrapper
{
public:
wrapper() {m_obj = new X;}
X* m_obj;
....
// exposed to the managed code to be able to
// talk to the API foobar method
int wrappedFoobar(int b, int c)
{
TypeB* bTmp = new TypeB(b);
TypeC* cTmp = new TypeC(c);
TypeA* aTmp = m_obj->foobar(bTmp, cTmp);
return aTmp->m_nInt;
}
}
This is EXTREMELY cumbersome if I want to use large parts of the API... or
not even doable if the types are really complex. Is there a way to reach
the unmanaged API where I'm not forced to practically rewrite the entire
library in managed code?
PLEASE, reply also to (e-mail address removed).
Sincerely,
/Tommy
application.
Now, the only way, as I've understood it, is to go the Managed Extensions
for C++ way. This means I have to write a wrapper between unmanaged API and
my managed app.
Now on to the question:
If there's an unmanaged API class called X with a defined method
TypeA* foobar(TypeB* b, TypeC* c);
then how can my managed code (my c# app) deal with the problem of inputing
TypeB and TypeC since they are not known or compatible with managed code,
and how should my c# app deal with the TypeA* return type?
Is there a way to "use" the unmanaged types "as they are" in the managed
code (maybe by uisng the API include files?) or do I have to do something
like this in my wrapper:
TypeA, TypeB and TypeC consists only of a public int member for simplicity.
public __gc class wrapper
{
public:
wrapper() {m_obj = new X;}
X* m_obj;
....
// exposed to the managed code to be able to
// talk to the API foobar method
int wrappedFoobar(int b, int c)
{
TypeB* bTmp = new TypeB(b);
TypeC* cTmp = new TypeC(c);
TypeA* aTmp = m_obj->foobar(bTmp, cTmp);
return aTmp->m_nInt;
}
}
This is EXTREMELY cumbersome if I want to use large parts of the API... or
not even doable if the types are really complex. Is there a way to reach
the unmanaged API where I'm not forced to practically rewrite the entire
library in managed code?
PLEASE, reply also to (e-mail address removed).
Sincerely,
/Tommy