473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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

Jul 22 '07 #1
5 2418
sherifffruitfly wrote:
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
Jul 22 '07 #2
On Jul 21, 10:52 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospamwr ote:
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

Jul 22 '07 #3

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:%2****************@TK2MSFTNGP05.phx.gbl...
sherifffruitfly wrote:
>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.
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.

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


Jul 23 '07 #4
sherifffruitfly wrote:
On Jul 21, 10:52 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospamwr ote:
>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#?
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
Jul 25 '07 #5
On Jul 24, 8:14 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospamwr ote:
sherifffruitfly wrote:
On Jul 21, 10:52 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospamwr ote:
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#?

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!

Jul 25 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Dave | last post by:
Hi, I have done some research, trying to Clear The Screen in java code. The first option was the obv: system.out.print("\n\n\n\n\n\n\n\n\n\n\n\n"); then i heard about this method:...
10
by: cppdev | last post by:
Hi All! I want to clear the string contents from sensitive information such as passwords, and etc. It's always a case that password will appear as string at some point or another. And i feel...
1
by: knormand | last post by:
I have an older MFC C++ app with some new Managed C++ being thrown in. Recently I turned on the /clr flag for one of my old .cpp files. I then placed '#pragma unmanaged' just below my #include...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
1
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the...
3
by: _BNC | last post by:
I have an old C DLL that I want to access via C#. I'm doing this via an outer DLL that wraps the old C DLL in an unmanaged C++ class, which is in turn wrapped in a Managed C++ class. Both these...
2
by: Jon Slaughter | last post by:
How difficult is it for one to integrate unmanaged C++ into C#? I know for functions one can use DLLimport but how does one go about doing it for classes? Do I have to completely reimplement the...
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
0
by: hanthehead | last post by:
In order to use a C# dll from our unmanaged C++ project I have created a mixed managed\unmanaged c++ dll. This dll is passed an unmanaged class which contains vector<CDBRecord> m_vecRecords member...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.