Jump to content
  • Advertisement
Sign in to follow this  
adam17

Windows Forms with C++

This topic is 3495 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ive been playing with windows forms in visual studio express, but im getting a little frustrated. i cannot find any tutorials on how to use windows forms 2.0 with c++ and without .NET. is it possible? whenever i add a form to my program, visual studio wants to change everything to a CLR environment. is there anything i can do or do i have to use .NET? btw what is different about CLR and C++? thanks -adam

Share this post


Link to post
Share on other sites
Advertisement
that was QUICK!! thanks!

is there a way that i can build the interface in .net, but have all of my background code in c++? i realize that i cannot access the form itself with c++.

Share this post


Link to post
Share on other sites
The simple reason because you cannot find any tutorial (or few) is because, when people use Visual Studio (not Express generally) windows forms are intended to be using the MFC (Microsoft Foundation Class), or better when they make Windows applications they intend MFC and they use dialog boxes as a sort of "form", I haven't seen much forms used either, anyway MFC is present as a feature only (as far as I know) for Visual Studio Standard and above. It's true that form use the CLR (the Common Language Runtime) which is engine that runs .NET programs (most like Java Runtime Environment), but I believe that forms can be done without that, let's say, Visual C++ 6 like, which was a pre-.NET compiler. I personally don't know much about those "WinForms 2.0", but, though the base concept might be wrong, it's not that true that you need .NET to run windows forms with C++, that's for example what we do in game engine when we use dialog boxes... we don't use .NET for that, and they behave just like forms in a certain way. What you really need to grasp are what Microsoft calls CommonControls (otherwise I used dialogs till today beign totally clueless :) ).

Share this post


Link to post
Share on other sites
Quote:
Original post by adam17
ive been playing with windows forms in visual studio express, but im getting a little frustrated. i cannot find any tutorials on how to use windows forms 2.0 with c++ and without .NET. is it possible? whenever i add a form to my program, visual studio wants to change everything to a CLR environment. is there anything i can do or do i have to use .NET? btw what is different about CLR and C++?

thanks
-adam


As SiCrane stated, it's not possible to directly use Windows Forms from C++ without using C++/CLI.

To answer the second question: C++ compiles down to native x86/x64 machine code, while C++/CLI and its predecessor Managed C++ compile down to CIL (Common Intermediate Language) which the CLR (Common Language Runtime) Just-In-Time compiles to native code at runtime. By compiling to CIL, C++/CLI can interact with both managed and unmanaged code.

That aside, what is your intended purpose for the forms? I've had a great deal of success writing C++/CLI wrappers for Windows Forms functionality.

Share this post


Link to post
Share on other sites
Quote:
Original post by nuvem
Quote:
Original post by adam17
ive been playing with windows forms in visual studio express, but im getting a little frustrated. i cannot find any tutorials on how to use windows forms 2.0 with c++ and without .NET. is it possible? whenever i add a form to my program, visual studio wants to change everything to a CLR environment. is there anything i can do or do i have to use .NET? btw what is different about CLR and C++?

thanks
-adam


As SiCrane stated, it's not possible to directly use Windows Forms from C++ without using C++/CLI.

To answer the second question: C++ compiles down to native x86/x64 machine code, while C++/CLI and its predecessor Managed C++ compile down to CIL (Common Intermediate Language) which the CLR (Common Language Runtime) Just-In-Time compiles to native code at runtime. By compiling to CIL, C++/CLI can interact with both managed and unmanaged code.

That aside, what is your intended purpose for the forms? I've had a great deal of success writing C++/CLI wrappers for Windows Forms functionality.


im wanting to build a simple mp3 player. i have it running smoothly as a command line program. now i want to add an interface. the new windows forms have a lot of nice features vs simple buttons and text boxes from the old forms.

is there a way to build an interface with the new forms and without having to port all of my current program to .net?

Share this post


Link to post
Share on other sites
Quote:


As SiCrane stated, it's not possible to directly use Windows Forms from C++ without using C++/CLI.



That's something I've never understood, seriously. It's ok that forms use a CLI, and you have to install Redistributables form Visual Studio and so on, but... does that means that just to use Common Controls you need to run .NET?

I mean, I tested my dialogs on a non-.NET machine back then, and it ran fine..
I don't get it

So forms do something more than just using common controls inside a window (which was what I though, but feel free to prove me that I'm wrong) which requires .NET framework to be running?

Sorry for intruding your request adam...


Share this post


Link to post
Share on other sites
Quote:
Original post by adam17
is there a way to build an interface with the new forms and without having to port all of my current program to .net?

Absolutely. You have two options:
1. Compile your program as a DLL and use P/Invoke to call the functions you expose.
2. Write a wrapper in C++/CLI for your interface that allows your program to adjust the UI and recieve events from it.

Since it's much less work, I recommend the first option.

Quote:
Original post by Yoio
That's something I've never understood, seriously. It's ok that forms use a CLI, and you have to install Redistributables form Visual Studio and so on, but... does that means that just to use Common Controls you need to run .NET?

Not at all. Windows Forms is a portion of the .NET Framework. Common Controls are native Win32, and thus have no dependency on .NET.

Share this post


Link to post
Share on other sites
Quote:
Original post by nuvem
Absolutely. You have two options:
1. Compile your program as a DLL and use P/Invoke to call the functions you expose.
2. Write a wrapper in C++/CLI for your interface that allows your program to adjust the UI and recieve events from it.

Since it's much less work, I recommend the first option.


do you know of any good places i should look to learn DLLs?

Share this post


Link to post
Share on other sites
Quote:
Original post by adam17
Quote:
Original post by nuvem
Absolutely. You have two options:
1. Compile your program as a DLL and use P/Invoke to call the functions you expose.
2. Write a wrapper in C++/CLI for your interface that allows your program to adjust the UI and recieve events from it.

Since it's much less work, I recommend the first option.


do you know of any good places i should look to learn DLLs?


Here's a good tutorial, complete with an example of how to call the functions from C#:

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!