473,399 Members | 3,038 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,399 software developers and data experts.

your experiences on porting code to C++/CLI, please

Ian
I would like to hear from others who have considered and/or ported code from
traditional C++ to C++/CLI.

The class library I am considering porting to C++/CLI was written in
traditional C++ with STL and a touch of MFC. It represents the back end to
my applications and, among a number of other things, it performs all file
I/O and data management operations (i.e. no GUI). Why would I consider
porting it to C++/CLI when it works just fine now? I consider myself to be
somewhat less than the average developer because I have no formal training
in software development but rather picked it up out of necessity. When MS
created dot.net it probably had guys like me in mind. Dot.net promises to
make it much easier and faster for me to develop applications. While
develpers more talented than myself can easily get by with pre-dot.net
technology, I have not been so fortunate. The information I've read so far
indicates it will be much easier for me to work with SQL, XML, data bases
and, you name it, in dot.net.

Having said the above, my current impression (and admittedly I have only
limited experience working with C++/CLI) is a port is clearly not a trival
task particularly because the libarary makes extensive use of STL with a
touch of MFC (i.e. CString and CFile. I am beginning to think it would be
better to rewrite the library from scratch over a period of 6-10 months then
to try porting existing code. I'll spend another week or two running more
tests and doing some more research. But I would appreciate hearing from
other C++ user about their experiences in porting their code to C++/CLI (or
even C# for that matter).

Thank you in advance for your input and comments,
Ian
Oct 13 '06 #1
4 1949
Ian wrote:
The class library I am considering porting to C++/CLI was written in
traditional C++ with STL and a touch of MFC. It represents the back end to
my applications and, among a number of other things, it performs all file
I/O and data management operations (i.e. no GUI). Why would I consider
porting it to C++/CLI when it works just fine now?
I don't know about you, but I don't even consider rewriting my back-end
in C++/CLI. I don't use MFC, and I don't use any other framework for
non-visual code (I have a Borland background, but learned years ago to
separate my non-visual code from all GUI-frameworks, so I have no IDE /
compiler dependencies for my back-end). I use STL and boost::shared_ptr,
which compile fine in C++/CLI as unmanaged code. It would be a
tremendous amount of work to rewrite everything, which is unnecessary,
unless the code really has to run in a .NET virtual machine. On the
contrary, I still develop new non-GUI code in ISO C++, without using any
GUI-related framework features.

What I do, instead of rewriting code, I just wrap it into ref classes.
It's easier than putting a COM wrapper around C++ code, it's just
boring, it involves duplicating your public API. But once it's done,
it's available for any .NET language.

Fortunately I don't rely on MFC classes, but I don't see why you
couldn't junk link MFC to a mixed-mode project. I've used native DLLs
from mixed-mode projects, my own and 3rd party as well.

Tom
Oct 16 '06 #2
Ian
"Tamas Demjen" <td*****@yahoo.comwrote in message
news:eT**************@TK2MSFTNGP04.phx.gbl...
Ian wrote:
Fortunately I don't rely on MFC classes, but I don't see why you couldn't
junk link MFC to a mixed-mode project. I've used native DLLs from
mixed-mode projects, my own and 3rd party as well.

Tom
Hello Tom,

I discovered this weekend that I can take existing code + STL and compile it
in CLR mode (I still haven't figured out how to do this with MFC but I'm
working on it). But this appears to be what you have been doing all along.
The chapters "Unsafe/Unmanaged C++" in Fraser book (Pro Visual C++/CLI),
various NG postings and several codeproject articles (e.g.
http://www.codeproject.com/useritems/usingcppdll.asp) lead me to believe I
would have to use P/Invoke to access my class libraries.

My backend code is non-GUI so based on the your information I should be able
to mix my class libraries with managed C++ and avoid porting my class
libraries to dot.net.

You mentioned you wrap your non-GUI ISO-C++ code in ref classes. Why would
you do this if you can simply call these new functions and/or objects from
unmanaged code? That is, why would you add the overhead of wrapping
unmanaged code in ref classes?
Thanks for your input,

Ian
Oct 16 '06 #3
Ian wrote:
The chapters "Unsafe/Unmanaged C++" in Fraser book (Pro Visual C++/CLI),
various NG postings and several codeproject articles (e.g.
http://www.codeproject.com/useritems/usingcppdll.asp) lead me to believe I
would have to use P/Invoke to access my class libraries.
It Just Works. I just call the functions. I don't use p/invoke, the
point of C++/CLI is that you can mix native and managed calls in the
same code. You just have to marshal your data when they're non-trivial
types. An integer, for example, can be passed as it is.
You mentioned you wrap your non-GUI ISO-C++ code in ref classes. Why would
you do this if you can simply call these new functions and/or objects from
unmanaged code?
You're right, it's often not necessary, as a managed method can directly
instantiate and call unmanaged objects. It's always up to you if you
feel wrapping necessary.
That is, why would you add the overhead of wrapping
unmanaged code in ref classes?
If you're a library vendor, for example. If I decide to wrap something,
it's also a specialization at the same time. I would hardly ever want to
wrap an entire native class library directly into .NET objects the way
they are. I would take my general-purpose native library, implement the
functionality I needed for a particular application, and wrap only that
portion, for example, to be called from a C# GUI.

..NET's biggest advantage (in addition to the RAD GUI feature) is its
component model. Native DLLs are very painful to use, and can't easily
be used in a portable plugin architecture. If you use STL classes in
exported functions, you have to compile the DLL and the EXE with the
same vendor's same compiler using the same settings. You're not allowed
to throw exceptions across DLL boundaries. You can't dynamically import
DLLs (there's no way to map a constructor with GetProcAddress). .NET
solves all these problems, and a lot more. It also settles the language
flames -- if someone wants to use VB to write a plugin to my
application, that's possible too. So these are the main reasons of
wrapping, mainly for interfacing, componentizing. I don't wrap my own
low-level libraries, I just call them with IJW.

Note that I don't have production code in .NET yet. I don't want to make
the impression that I'm an experienced .NET programmer, because I'm not.
I just spent a little time researching it. Naturally, the very first
thing I did was implement a dynamically loaded plugin, because that was
my first interest, and learning to effectively mix native code with
managed GUI.

Tom
Oct 16 '06 #4
Ian

"Tamas Demjen" <td*****@yahoo.comwrote in message
news:eu****************@TK2MSFTNGP05.phx.gbl...
Ian wrote:
>The chapters "Unsafe/Unmanaged C++" in Fraser book (Pro Visual C++/CLI),
various NG postings and several codeproject articles (e.g.
http://www.codeproject.com/useritems/usingcppdll.asp) lead me to believe
I would have to use P/Invoke to access my class libraries.

It Just Works. I just call the functions. I don't use p/invoke, the point
of C++/CLI is that you can mix native and managed calls in the same code.
You just have to marshal your data when they're non-trivial types. An
integer, for example, can be passed as it is.
>You mentioned you wrap your non-GUI ISO-C++ code in ref classes. Why
would you do this if you can simply call these new functions and/or
objects from unmanaged code?

...

Note that I don't have production code in .NET yet. I don't want to make
the impression that I'm an experienced .NET programmer, because I'm not. I
just spent a little time researching it. Naturally, the very first thing I
did was implement a dynamically loaded plugin, because that was my first
interest, and learning to effectively mix native code with managed GUI.

Tom
I've just started testing dot.net code and your information has been
helpful. Thanks again and all the best.

Ian

Thanks again
Oct 16 '06 #5

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

Similar topics

5
by: Kenton Groombridge | last post by:
Hi, I previous posted this in a gcc and g++ groups since that is the compiler I am working with, but I didn't get any response. Hopefully these are the right groups for this question. I am...
19
by: navin_2016 | last post by:
Hi, Can somone please describe the problems one would face when we try to port a software written in C to another platform some of them being endianness ,alignment,data types etc ? It would be...
9
by: Tony Johansson | last post by:
Hello! Some information to be able to have a change to answer the question. Assume I have a large system developed in MFC. In this system we have only C++ code so no other language exist. This...
245
by: Vortex Soft | last post by:
http://www.junglecreatures.com/ Try it and tell me what's happenning in the Microsoft Corporation. Notes: VB, C# are CLS compliant
2
by: sandip desale | last post by:
Dear All, We have a Tcl/Tk application written using Python 2.2. Using this application we want to call some customizable Java APIs. I tried porting Tcl/Tk application to Jython but not able to do...
34
by: subramanian100in | last post by:
Is there any difference between porting and migrating. Kindly explain
5
by: shobhah | last post by:
Hi, We have a complete succsssfully working product on 32bit sparc solaris machine for which compiler used is CC 5.8 Now we are migarting our product from 32 bit to 64bit sparc solaris machine....
6
by: =?Utf-8?B?RGlwZXNoX1NoYXJtYQ==?= | last post by:
Hi all, I am porting an code written in VC++ to VC.Net to make it manage. But in Managed VC we dont use "const" keyboard at all. but my code is using it very frequently, so is their any...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.