Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / September 2003

Tip: Looking for answers? Try searching our database.

.NET calling native c++ and threading

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 29 Sep 2003 20:00 GMT
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
Kumar Gaurav Khanna [.NET MVP] - 30 Sep 2003 06:06 GMT
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,
> --------------------------------------------------

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.