I'd like to call C++ from C#. I don't want to use COM becuase I want to be
able to call the C++ code from device-driver side fn's as well, and I need
to be able to target portable devices with the CF, so that leaves me with
PInvoke. Questions:
(1) Is there anything more than PInvoke available, so I don't need to write
wrappers to flatten the C++ object hierarchies into a bunch of extern "c"'s?
(For languages such as Python there are tools such as SWIG, Boost, PyInline,
CXX, Weave, etc., that help automate this process.)
(2) The C++ code creates several threads which it uses to do network i/o.
Will the CLR be okay with this? Is the message pump the best way to tell
managed code that a new event has occurred?
thanks,
mike
Hi!
Yes, there's another option than PInvoke: Managed C++. You could use MC++ to
create managed C++ wrapper classes around your existing unmanaged C++
classes. Your .NET application will call the methods against the managed C++
class which shall internally delegate calls to the unmanaged class. Infact,
this approach gives better interop, thats more efficient that PInvoke, with
lesser overhead.
Threads created by unmanaged code has got nothing to do with the CLR. So,
yes, CLR will be "okay" with it.
You could create an event handle and have the managed code wait on it.
Consider using WaitHandle class for the same.
Regards,
--------------------------------------------------
Kumar Gaurav Khanna
Microsoft MVP - .NET, MCSE Windows 2000/NT4, MCP+I
WinToolZone - Spelunking Microsoft Technologies
http://www.wintoolzone.com/
OpSupport - Spelunking Rotor
http://opsupport.sscli.net/
> I'd like to call C++ from C#. I don't want to use COM becuase I want to be
> able to call the C++ code from device-driver side fn's as well, and I need
[quoted text clipped - 10 lines]
> thanks,
> mike
Mike - 30 Sep 2003 16:32 GMT
Thanks... I knew about MC++ but always thought it was such a strange "worst
of both worlds" approach -- but I guess the glass is really half-full when
it's needed for this type of application. I assume I should make an "empty"
managed subclass the UM code as my wrapper? What the difference between
writing a mangaged wrapper to my UM code, or just throwing the switch and
compiling the C++ in IL (in this case I have all the source), assuming that
I can access the few (socket) libs I want from the framework?
thanks
> Hi!
>
[quoted text clipped - 13 lines]
> Regards,
> --------------------------------------------------