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 / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

Clear steps to wrap an unmanaged c++ class code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sherifffruitfly - 22 Jul 2007 03:38 GMT
Hi,

I want to use a c++ class in my c# application. Are there any clear
step-by-step tutorials on an easy way to achieve this? All I've been
able to find are relatively complicated discussions about managed
extensions and what-not. I also saw someone make the suggestion that
they compile their c++ class as a COM component, but I have no idea
how to do this either. I'm just looking for any straightforward way to
make my c++ class available to c#.

Thanks for any tips,

cdj
Carl Daniel [VC++ MVP] - 22 Jul 2007 06:52 GMT
> Hi,
>
[quoted text clipped - 5 lines]
> how to do this either. I'm just looking for any straightforward way to
> make my c++ class available to c#.

In general, there is no straightforward way - unless your C++ class happens
to already be a COM class.  For any other case, you need to learn and
understand the intricacies of native/managed interop.  There are a myriad of
possibilities, depending on the class and how it's used - so you're unlikely
to find a step by step tutorial that tells you exactly what you need to
know.

If you can provide more information about the C++ class, I or others can
give you more detailed help.

What does the interface of the C++ class look like?  How is it used?  How is
it's lifetime managed?  Does it make callbacks from arbitrary threads?
These and potentially many other questions may influence your options for
using this class from C#.

-cd
sherifffruitfly - 22 Jul 2007 18:41 GMT
On Jul 21, 10:52 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospam> wrote:

> In general, there is no straightforward way - unless your C++ class happens
> to already be a COM class.  For any other case, you need to learn and
> understand the intricacies of native/managed interop.

Dammit all to hell - lol!

> If you can provide more information about the C++ class, I or others can
> give you more detailed help.
[quoted text clipped - 3 lines]
> These and potentially many other questions may influence your options for
> using this class from C#.

Rather than answer these questions piecemeal, I'll just point you to
the code - it's very short and simple, though I'm unfamiliar with
winsock/tcpip stuff in c++:

http://random.irb.hr/index.php

Perhaps it would be simplest to simply rewrite the code in c#?

Thanks for your reply!

cdj
Carl Daniel [VC++ MVP] - 25 Jul 2007 04:14 GMT
> On Jul 21, 10:52 pm, "Carl Daniel [VC++ MVP]"
> <cpdaniel_remove_this_and_nos...@mvps.org.nospam> wrote:
[quoted text clipped - 20 lines]
>
> Perhaps it would be simplest to simply rewrite the code in c#?

If it's short and simple, it probably IS easier to simply rewrite the code
in C#.  The .NET BCL has very good support for doing TCP/IP programming
(more efficient than the vast majority of native C++ apps that use sockets
for communications).

-cd
sherifffruitfly - 25 Jul 2007 05:37 GMT
On Jul 24, 8:14 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospam> wrote:
> > On Jul 21, 10:52 pm, "Carl Daniel [VC++ MVP]"
> > <cpdaniel_remove_this_and_nos...@mvps.org.nospam> wrote:
[quoted text clipped - 27 lines]
>
> -cd

Cool - thanks!
Ben Voigt [C++ MVP] - 23 Jul 2007 19:10 GMT
>> Hi,
>>
[quoted text clipped - 12 lines]
> you're unlikely to find a step by step tutorial that tells you exactly
> what you need to know.

I don't know about that.  In many cases, changing "class" to "public ref
class" is more than halfway there.

> If you can provide more information about the C++ class, I or others can
> give you more detailed help.
[quoted text clipped - 5 lines]
>
> -cd

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.