Search:
Namespaces
Discussions
.NET v1.1
Feedback
VC++6 MFC migration managed C++(windows form )
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.general
.
Post a new message to this list...
Bredal Jensen
I want to port my MFC (VC++6) application to manageg VC ++. 7. I want to do
this because some things are much better done with C#. So i could write a C#
class and use in
my VC++ code as Languague interoperability is one of the main features of
the .Net
framework. I know my application would have to obey to the CTS (common type
specification) but my main concerns are the MFC stuff!
I do not really know which options you have with windows forms. Can they do
what MFC
can do? How about functions pointers. How does managed C++ deal with this?
Maybe this is not the right place to post this, but any usefull comment will
be very
appreciated.
Thanks
Reply to this message...
Niki Estner
"Bredal Jensen" <
Click here to reveal e-mail address
> wrote in
news:
Click here to reveal e-mail address
...
[Original message clipped]
First port it to unmanaged VC++ 7. MFC 6 and MFC 7 do have some differences.
After that, compiling the code as managed code is usually only a compiler
switch.
[Original message clipped]
You can still do anything in managed C++; You only have to obey CTS rules
for the types you want to expose to other languages (like C#)
[Original message clipped]
IMO it would be a good idea to convert your MFC app to WinForms, however
there's no real need to do that.
> How about functions pointers. How does managed C++ deal with this?
It's managed, but it's still C++. You have const types, templates, function
pointers, void pointers...
If you can't compile your C++ code as managed code, you could still use COM
interop.
Hope this helps,
Niki
Reply to this message...
Bredal Jensen
Well thanks for your answer, i have already compiled with Vc++.7 .
So what is this compiler switch i have to add?
"Niki Estner" <
Click here to reveal e-mail address
> wrote in message
news:%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Niki Estner
"Bredal Jensen" <
Click here to reveal e-mail address
> wrote in
news:
Click here to reveal e-mail address
...
[Original message clipped]
Go to the properties of your project - general tab - switch "use managed
extensions" to "yes".
You may have to resolve a few conflicts with other project settings, but
afterwards you should be able to include managed code into your application.
Niki
Reply to this message...
Bredal Jensen
Many thanks , this sounds so great to me , i never though it would be so
simple.
Well , i did that and now it says :
"Command line error D2016 : '/RTC1' and '/clr' command-line options are
incompatible"
"Niki Estner" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Niki Estner
"Bredal Jensen" <
Click here to reveal e-mail address
> wrote in
news:
Click here to reveal e-mail address
...
[Original message clipped]
Yes, I had the same experience with converted VC6 projects. You can either
create a new dummy MFC project in VC7 and "copy" all compiler settings (new
projects are configured so they can be compiled with managed extensions), or
you can adjust the compiler switches one by one with each error;
Have a look at the MSDN article on the "/clr" compiler switch, it should
contain all the information you need.
Niki
Reply to this message...
Bredal Jensen
I'm having trouble finding where these "compiler settings" can be found.
I'm using visual studio ..Net
"Niki Estner" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Niki Estner
"Bredal Jensen" <
Click here to reveal e-mail address
> wrote in
news:
Click here to reveal e-mail address
...
[Original message clipped]
Really? It's quite easy to find information on them...
Example: /RTC1;
Open up MSDN; Go to the "Index" Tab; Enter "/RTC1"; Read the article,
especially this paragraph:
"To set this compiler option in the Visual Studio development environment:
1. Open the project's Property Pages dialog box. For details, see Setting
Visual C++ Project Properties.
2. Click the C/C++ folder.
3. Click the Code Generation property page.
4. Modify one or both of the following properties: Basic Runtime Checks or
Smaller Type Check."
Niki
Reply to this message...
Bredal Jensen
Now my program compiles as manages C++ and actually runs.
Is that all i had to do to run as managed C++?
Well i must say your informations are very accurate and i'm
really thankfull for all these help.
I still have questions though. I now decided to write one of my user
interface part as a C# "windows control" .
I need to do the equivalent of (Postmessage or SendMessage) plus send data
like with (wParam and lParam) . Is there a way of doing this?
Again thank you so much....
"Niki Estner" <
Click here to reveal e-mail address
> skrev i en meddelelse
news:uZysKC$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Niki Estner
"Bredal Jensen" <
Click here to reveal e-mail address
> wrote in
news:
Click here to reveal e-mail address
...
[Original message clipped]
It's not 100% managed code yet, but you can reference managed assemblies and
create managed types. The possibility to have managed and unmanaged code in
one assembly is one of the major advantages of managed C++. The price is
that you often have to use keywords like __gc or __value to tell the
compiler which way to go.
[Original message clipped]
You can still P/Invoke SendMessage and PostMessage with the DllImport
attribute, and every control has a protected virtual method "WndProc".
However, it's usually a bad idea to use them if you can avoid it: First of
all, those "wParam/lParam" parameters tend to disturb the GC if they carry
pointers; They are ugly to debug, and error-prone.
Depending on what you want to do, I'd suggest having a deeper look at
events, delegates, interfaces (for loose-coupling), or the
Control
.Invoke
method (for inter-thread communication).
Niki
Reply to this message...
Bredal Jensen
What i want to do:
I was once C++ addict but since i tried C#, i just don't want to use
too much of C++ anymore.
I have this huge MFC application and it needs new features. I then want to
do all
new developement in C# and work my way through like this.
An alternative is a whole rewrite in C# , but it does not seem like our
budget
allow this for now.
So here is what want to do. Did that sound Crazy? ;)
"Niki Estner" <
Click here to reveal e-mail address
> skrev i en meddelelse
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Niki Estner
"Bredal Jensen" <
Click here to reveal e-mail address
> wrote in
news:%
Click here to reveal e-mail address
...
[Original message clipped]
No: thanks to managed C++ you can port an application step-by-step without
pain.
But you should always keep the architecture of your application in mind: If
you have to add a new feature which you would have put into a separate DLL
anyway, fine write it in managed code. However, if you have to add a feature
to an existing class, you should either write it in C++, or port the whole
class (or maybe even bigger chunks of your application) to C#. Otherwise
your application will be a mess quite soon.
Also, you should identify parts of your application that would profit most
from .NET (especially the ones that are bound to change), and port them to
C# when you have the time (you'll be lucky you did when you don't have the
time any more).
I think that's a good way to go, and if you do it right, it should save you
lots of time.
Niki
Reply to this message...
Bredal Jensen
well , i'm mostly going to build "windows control library" and use "Add
reference" and instantiate the classes.
Actually i though i could also just instantiate a C# class not in a binary
form. shouldn't that in theory be possible?
"Niki Estner" <
Click here to reveal e-mail address
> skrev i en meddelelse
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Niki Estner
"Bredal Jensen" <
Click here to reveal e-mail address
> wrote in
news:
Click here to reveal e-mail address
...
[Original message clipped]
use the "new" operator to instantiate classes. adding a reference only makes
the classes in an assembly visible, it doesn't instantiate them yet.
[Original message clipped]
The C# class would have to be compiled, so it has to be in a binary form;
You can compile it at runtime, but I'm not sure if that's what you mean.
Niki
Reply to this message...
Bredal Jensen
What i mean is :
making my C# class available to a c++ class with:
"using Mynaspace.Myclasss "
and Myclass mc = new Myclass(....
"Niki Estner" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Bredal Jensen
An other issue.
Now that my code is Dot net "ready"
i though i could just use fx: using System.Net . in my C++ file.
But that does not seem to work. I recall you saying my code
was not 100% manged . is that why i can not do this?
"Bredal Jensen" <
Click here to reveal e-mail address
> skrev i en meddelelse
news:%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Niki Estner
"Bredal Jensen" <
Click here to reveal e-mail address
> wrote in
news:
Click here to reveal e-mail address
...
[Original message clipped]
Did you reference the right assemblies? I think this namespace is
implemented in System.dll - you'll have to add a reference to it.
[Original message clipped]
You should be able to do this; However it is possible that you will not be
able to use managed code in some of your functions because they already
contain native code; simply create a new empty function then, put the
managed code in it , and call it from your unmanaged function.
Niki
Reply to this message...
Bredal Jensen
I think i have a problem my visusal studio installation. i need to do a
reinstall.
I can not even see the add reference option .
But you are right i have not added a reference to "System.dll ".
I 'll try again later when i ahve a reliable visual studion installation.
"Niki Estner" <
Click here to reveal e-mail address
> skrev i en meddelelse
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Niki Estner
"Bredal Jensen" <
Click here to reveal e-mail address
> wrote in
news:uOLjy%
Click here to reveal e-mail address
...
[Original message clipped]
Really? Select your project in the solution explorer and choose "Add
Reference" from the project menu.
You can also do the same from the source code with the "#using" preprocessor
directive.
Niki
Reply to this message...
Bredal Jensen
I can not see it in the project menu .
The IDE "Itself" also prompted me to reinstall .
But before i do , could you show code snippet of how to use "#using " thing.
Assum i want to get the list of my local ip/ips . I know
this can be done with Ip helper but i guess it must be much
more straight forward using .Net.
"Niki Estner" <
Click here to reveal e-mail address
> skrev i en meddelelse
news:u%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Bredal Jensen
Before i totally go for this dot net thing. I have to say that
my application is a videosurveillance program and i'm thinking
if i 'll alter performance considerably as i totaaly rely on the dotnet
runtime
for code generation.
Let me know what you think.
"Bredal Jensen" <
Click here to reveal e-mail address
> skrev i en meddelelse
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Niki Estner
"Bredal Jensen" <
Click here to reveal e-mail address
> wrote in
news:
Click here to reveal e-mail address
...
[Original message clipped]
In my experience, .NET creates quite fast code, and you can still implement
performance-critical code in managed C++, so I don't think that will be a
problem.
But, as always with performance: trust noone but your own benchmark.
Niki
Reply to this message...
Bredal Jensen
Hi Niki,
well i enjoyed your help so much and i 'm almost sure , i 'll need it again.
I just want to know where i can catch you when i encounter trouble ;).
I assum you are on this group , and i hope you 'll see my postings.
Best regard
JB
"Niki Estner" <
Click here to reveal e-mail address
> wrote in message
news:O7%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Niki Estner
"Bredal Jensen" <
Click here to reveal e-mail address
> wrote in
news:OVz$
Click here to reveal e-mail address
...
[Original message clipped]
I'll do my best
Niki
Reply to this message...
System.Web.UI.Control
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com