What is the best way to change a C ++ program to be used with pInvoke from C # .NET CF?
I have a large C ++ code base that makes extensive use of STL. Namely, iterators, container classes, and standard strings.
In addition to this, many light classes are passed by value.
I want to build C # gui ontop of this codebase for mobile devices for Windows mobile devices.
Is it worth it?
I managed to get some examples working using pInvoke to call C ++ code from C # .NET, but writing wrappers for each access point and for all return types of STL seems very complicated and ugly. Is there any other way, or am I a bit full?
BTW. Managed C ++ is not an option because it is not supported in any form of .NET CF.
- edit: I have one specific question regarding pinvoke.
Suppose you had a function returning a C ++ string by value
std::string foo () { return std::string ("Hi"); }
I understand that it cannot be called from C # using pinvoke, because there is no way to output the STL string, but my problem is that I canβt even write a shell without allocating a new array, because std :: string is not returned in heap.
char* foo2 () { return foo().c_str();
So my problem is how to wrap foo in a suitable pInvoke format without having to redistribute the whole line.
char* foo2 () { std::string f = foo(); char* waste = new char[f.length()+1]; strcpy (waste, f.c_str()); return f; }
The thought of doing above for each point at which I need to return std :: string is enough to make me give up trying to use C #.
Akusete
source share