470,602 Members | 1,728 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,602 developers. It's quick & easy.

VC++6 MFC migration managed C++(windows form )


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
Jul 21 '05 #1
23 2108
"Bredal Jensen" <Br***********@mimosa.com> wrote in
news:e4**************@TK2MSFTNGP15.phx.gbl...

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.
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.
I know my application would have to obey to the CTS (common type
specification) but my main concerns are the MFC stuff!
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#)
I do not really know which options you have with windows forms. Can they
do
what MFC can do?
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
Jul 21 '05 #2
Well thanks for your answer, i have already compiled with Vc++.7 .
So what is this compiler switch i have to add?



"Niki Estner" <ni*********@cube.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"Bredal Jensen" <Br***********@mimosa.com> wrote in
news:e4**************@TK2MSFTNGP15.phx.gbl...

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.
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.
I know my application would have to obey to the CTS (common type
specification) but my main concerns are the MFC stuff!
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#)
I do not really know which options you have with windows forms. Can they
do
what MFC can do?


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

Jul 21 '05 #3
"Bredal Jensen" <Br***********@mimosa.com> wrote in
news:ew**************@tk2msftngp13.phx.gbl...
Well thanks for your answer, i have already compiled with Vc++.7 .
So what is this compiler switch i have to add?


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
Jul 21 '05 #4
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" <ni*********@cube.net> wrote in message
news:et**************@TK2MSFTNGP12.phx.gbl...
"Bredal Jensen" <Br***********@mimosa.com> wrote in
news:ew**************@tk2msftngp13.phx.gbl...
Well thanks for your answer, i have already compiled with Vc++.7 .
So what is this compiler switch i have to add?
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

Jul 21 '05 #5
"Bredal Jensen" <Br***********@mimosa.com> wrote in
news:e3**************@TK2MSFTNGP11.phx.gbl...
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"


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
Jul 21 '05 #6
I'm having trouble finding where these "compiler settings" can be found.
I'm using visual studio ..Net


"Niki Estner" <ni*********@cube.net> wrote in message
news:Or**************@TK2MSFTNGP11.phx.gbl...
"Bredal Jensen" <Br***********@mimosa.com> wrote in
news:e3**************@TK2MSFTNGP11.phx.gbl...
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"
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

Jul 21 '05 #7
"Bredal Jensen" <Br***********@mimosa.com> wrote in
news:u1**************@TK2MSFTNGP14.phx.gbl...
I'm having trouble finding where these "compiler settings" can be found.
I'm using visual studio ..Net


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
Jul 21 '05 #8
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" <ni*********@cube.net> skrev i en meddelelse
news:uZ**************@TK2MSFTNGP14.phx.gbl...
"Bredal Jensen" <Br***********@mimosa.com> wrote in
news:u1**************@TK2MSFTNGP14.phx.gbl...
I'm having trouble finding where these "compiler settings" can be found.
I'm using visual studio ..Net


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

Jul 21 '05 #9
"Bredal Jensen" <br****@jensen.dk> wrote in
news:O9**************@TK2MSFTNGP11.phx.gbl...
Now my program compiles as manages C++ and actually runs.
Is that all i had to do to run as managed C++?
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.
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?


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
Jul 21 '05 #10
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" <ni*********@cube.net> skrev i en meddelelse
news:eo**************@tk2msftngp13.phx.gbl...
"Bredal Jensen" <br****@jensen.dk> wrote in
news:O9**************@TK2MSFTNGP11.phx.gbl...
Now my program compiles as manages C++ and actually runs.
Is that all i had to do to run as managed C++?
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.
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?


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

Jul 21 '05 #11
"Bredal Jensen" <br****@jensen.dk> wrote in
news:%2****************@TK2MSFTNGP09.phx.gbl...
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? ;)


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
Jul 21 '05 #12
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" <ni*********@cube.net> skrev i en meddelelse
news:uZ**************@tk2msftngp13.phx.gbl...
"Bredal Jensen" <br****@jensen.dk> wrote in
news:%2****************@TK2MSFTNGP09.phx.gbl...
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? ;)
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

Jul 21 '05 #13
"Bredal Jensen" <br****@jensen.dk> wrote in
news:ux**************@tk2msftngp13.phx.gbl...
well , i'm mostly going to build "windows control library" and use "Add
reference" and instantiate the classes.
use the "new" operator to instantiate classes. adding a reference only makes
the classes in an assembly visible, it doesn't instantiate them yet.
Actually i though i could also just instantiate a C# class not in a binary
form. shouldn't that in theory be possible?


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
Jul 21 '05 #14
What i mean is :

making my C# class available to a c++ class with:
"using Mynaspace.Myclasss "

and Myclass mc = new Myclass(....


"Niki Estner" <ni*********@cube.net> wrote in message
news:un**************@TK2MSFTNGP14.phx.gbl...
"Bredal Jensen" <br****@jensen.dk> wrote in
news:ux**************@tk2msftngp13.phx.gbl...
well , i'm mostly going to build "windows control library" and use "Add
reference" and instantiate the classes.
use the "new" operator to instantiate classes. adding a reference only

makes the classes in an assembly visible, it doesn't instantiate them yet.
Actually i though i could also just instantiate a C# class not in a binary form. shouldn't that in theory be possible?


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

Jul 21 '05 #15
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" <Br***********@mimosa.com> skrev i en meddelelse
news:%2****************@TK2MSFTNGP09.phx.gbl...
What i mean is :

making my C# class available to a c++ class with:
"using Mynaspace.Myclasss "

and Myclass mc = new Myclass(....


"Niki Estner" <ni*********@cube.net> wrote in message
news:un**************@TK2MSFTNGP14.phx.gbl...
"Bredal Jensen" <br****@jensen.dk> wrote in
news:ux**************@tk2msftngp13.phx.gbl...
well , i'm mostly going to build "windows control library" and use "Add reference" and instantiate the classes.


use the "new" operator to instantiate classes. adding a reference only

makes
the classes in an assembly visible, it doesn't instantiate them yet.
Actually i though i could also just instantiate a C# class not in a binary form. shouldn't that in theory be possible?


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


Jul 21 '05 #16
"Bredal Jensen" <br****@jensen.dk> wrote in
news:eF**************@TK2MSFTNGP12.phx.gbl...
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.
Did you reference the right assemblies? I think this namespace is
implemented in System.dll - you'll have to add a reference to it.
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?


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
Jul 21 '05 #17
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" <ni*********@cube.net> skrev i en meddelelse
news:u4**************@TK2MSFTNGP15.phx.gbl...
"Bredal Jensen" <br****@jensen.dk> wrote in
news:eF**************@TK2MSFTNGP12.phx.gbl...
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.


Did you reference the right assemblies? I think this namespace is
implemented in System.dll - you'll have to add a reference to it.
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?


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

Jul 21 '05 #18
"Bredal Jensen" <br****@jensen.dk> wrote in
news:uO****************@TK2MSFTNGP11.phx.gbl...
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 .


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
Jul 21 '05 #19
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" <ni*********@cube.net> skrev i en meddelelse
news:u%***************@TK2MSFTNGP15.phx.gbl...
"Bredal Jensen" <br****@jensen.dk> wrote in
news:uO****************@TK2MSFTNGP11.phx.gbl...
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 .
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

Jul 21 '05 #20
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" <br****@jensen.dk> skrev i en meddelelse
news:el**************@TK2MSFTNGP15.phx.gbl...
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" <ni*********@cube.net> skrev i en meddelelse
news:u%***************@TK2MSFTNGP15.phx.gbl...
"Bredal Jensen" <br****@jensen.dk> wrote in
news:uO****************@TK2MSFTNGP11.phx.gbl...
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 .


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


Jul 21 '05 #21
"Bredal Jensen" <br****@jensen.dk> wrote in
news:um**************@TK2MSFTNGP15.phx.gbl...
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.


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
Jul 21 '05 #22
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" <ni*********@cube.net> wrote in message
news:O7****************@TK2MSFTNGP09.phx.gbl...
"Bredal Jensen" <br****@jensen.dk> wrote in
news:um**************@TK2MSFTNGP15.phx.gbl...
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.
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

Jul 21 '05 #23
"Bredal Jensen" <Br***********@mimosa.com> wrote in
news:OV**************@TK2MSFTNGP11.phx.gbl...
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.


I'll do my best

Niki
Jul 21 '05 #24

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.