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

S

sherifffruitfly

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
 
C

Carl Daniel [VC++ MVP]

sherifffruitfly said:
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#.

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
 
S

sherifffruitfly

sherifffruitfly 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.

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#.

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
 
B

Ben Voigt [C++ MVP]

Carl Daniel said:
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.

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

Carl Daniel [VC++ MVP]

sherifffruitfly said:
Dammit all to hell - lol!


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#?

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
 
S

sherifffruitfly

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

Cool - thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top