convert Windows Forms Application in C++ to executable file - c++

I am using VS10 C++ and try to convert Windows Forms Application project to executable file: this what I did
select project-> properties -> configuration properties -> C/C++
-> Code Generation -> Runtime library
then I select Multi-threaded Debug(/MTd)
when I built my project I got the following error

A Windows Forms application depends on classes from the .NET Framework Base Class Library. To develop a Windows desktop application in C++ that does NOT depend on .NET, you should use the project template for a Microsoft Foundation Classes (MFC) Application instead. This type of project will compile as a native .exe, instead of a .NET assembly. (By the way, not sure why you would still be using Visual Studio 2010 for C++ development, when the free VS 2015 Community Edition fully supports C++11 and many features of C++14. I do not yet recommend VS 2017 however, since it is still very buggy for C++ development.)
EDIT: In Visual Studio 2017, there is another option (which was not available in VS 2015). If you choose the Windows Desktop Application project template, you will get a project that depends on neither .NET (aka CLR support) nor MFC. I have never tried this approach, but on the surface, it looks very similar to MFC. Again, so far I have found VS 2017 for C++ to be very buggy, so you might have a better experience using MFC in VS 2015 instead.

Related

How to NOT target any .NET Framework in Visual Studio 2010 for a C++ application

Is it possible to create a new Win32 C++ project in VS2010 that wouldn't target a .NET Framework? Visual Studio seems to refuse to create a project unless at least one .NET Framework version is selected as a target. It also refuses to load a project if .NET is not installed on a computer, even if SLN / VCXPROJ files do not contain any .NET references. If .NET is not installed, Visual Studio still demands to select a .NET Framework version, but since no versions are available, it refuses to create a new project. But what if I want my application to have nothing to do with .NET and to run on a computer that doesn't have .NET installed? (The operating system I'm using is Windows XP, although that shouldn't make a difference).
I took the following steps:
Uninstall .NET.
In Visual Studio 2010, go to File -> New -> Project.
In the New Project window, under Installed Templates, click "Win32 Project -- Visual C++". At this point, Visual Studio begins to demand to choose a target .NET Framework version.
[tl;dr]   Visual Studio 2010 has the .NET Framework 4.0 as a prerequisite. The VS 2010 setup installs it if necessary, and the IDE will not function correctly if the .NET components are manually uninstalled afterwards. Unmanaged C++ applications can still be built outside the IDE without any .NET installed, and the resulting binaries have no runtime dependencies on .NET. Repairing the VS 2010 installation restores the .NET components, and gets the IDE to work as expected.
The following was tried on a clean XP SP3 (virtual) machine, with a fresh install of VS 2010.
The setup lists .NET 4.0 as a prerequisite, and installs it if necessary.
Manually uninstalling the .NET 4.0 components from Add Remove Programs breaks the IDE.
Repairing the installation gets the IDE working again. The New Project dialog has a top level .NET Framework version dropdown that defaults to .NET Framework 4, which applies to all project types. including the unmanaged C++ projects. However, the selection has no bearing on unmanaged projects, which do not target, use, or otherwise require .NET.

How could I know if I'm developing a c++/cx or c++/WinRT UWP application?

I'm creating a c++ UWP application and I want this app to be c++/WinRT because I read that c++/cx is not supported anymore.
And this is how I created my application.
VS 2017 -> File -> New -> Project... -> Visual C++ -> Windows Universal -> Blank App (Universal Windows)
I'm sorry for this basic question but I couldn't find out if my app is a c++/WinRT or not.
C++/CX and C++/WinRT do not generate different application types. Even if C++/CX weren't supported anymore (it still is), an application compiled using C++/CX would still continue to run. C++/CX is purely a language-level compiler setting, that generates native code just like C++/WinRT.
You opt in to C++/CX by setting the /ZW (Windows Runtime Compilation) compiler option. If that compiler option isn't present, you aren't using C++/CX. The Blank App (C++/WinRT) project template (available after installing the C++/WinRT Visual Studio extension) doesn't set the /ZW compiler option. The Blank App (Windows Universal), on the other hand, does set the /ZW compiler option.

Failing to migrate a .NET C++ class library from VS 2008 to VS 2012

I have a C++ project that builds a .NET class library that targets the framework 3.5.
This project has been working seamlessly since ages and the classes can be used from, among others, C# applications. It was developed with Visual Studio 2008 Professional.
Now I need to migrate if to Visual Studio 2012 Professional. I have successfully converted the project.
I meet a first problem, which is that the target framework cannot be changed from the project Common Properties, the field is read-only.
I can work around this by editing the .vcxproj file to insert a TargetedFramework tag. The new version does appear in the Common Properties.
I am also able to add references to the .NET assemblies that the library needs (just System, System.Drawing and System.Windows.Forms). The class library compiles correctly to a Dll and I can see its content in the Object Browser.
Now if I try to use it in an application targeting a framework version below 4, I get the message
1>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.Targets(1605,5): warning MSB3258: The primary reference "MyClasses" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework.
I can't see where an indirect reference could come from (my explicit references are to v2.0.50727, which seem to be the file version for 2.0/3.0/3.5).
Do you have any explanation ?
(Expanding on Hans's correct comments)
Visual Studio supports .NET multi-targeting for the C++/CLI language by launching older versions of the C++ compiler.
As a result, the language features are inextricably linked to the .NET framework dependency -- with the newer compilers (Visual C++ 2010 and later), you get C++11 and C++14 features and .NET 4, with the older compilers (Visual C++ 2008 and before) you get .NET 2, but very little C++11 support.
To control this, there's a Platform Toolset selection in the Project Properties, but some manual project file editing is also required.
The Visual C++ Team wrote a blog post about C++ Managed Multi-Targeting in Visual Studio 2010... for later versions, read the documentation on MSDN.

General usage of c++ in visual studio

Is it possible to write a c++ code in Visual Studio without using c++.net?
I'm learning c++ at the moment - Using a book.
But I like the Visual Studio IDE but I don't know if it supports c++ or just c++.net.
I usually create a new (empty) directory and copy the source file(s) into that directory, then when creating the Visual Studio project using the name of the directory. To create a standard C++ console program, choose "... console application", then click on next, clear the check boxes below "empty project", and check "empty project". Once you're into the project, click on project, and "add existing item" to add the source file name(s).
If you want 64 bit mode, you'll need to right click on the project name, then properties, then configuration manager, then new, and select x64. It doesn't matter if you do this for debug or release build, it will set x64 mode for both build modes.
Yes, you can. Visual studio supports two types of C++ applications:
C++/CLI (also called managed C++) - Under Visual Studio project wizard, these kind of projects are grouped under CLR
Native C++ - Under Visual Studio project wizard, these are the projects grouped under Win32, MFC, ATL
Note, however, that you can always turn a project from native to managed and vice versa by going into the project properties and switching on/off the Common Language Runtime Support (/clr), so make sure this option is turned off (No CLR).
Also, be aware that different C++ compilers not always support the same C++ features (even if they are part of the standard), and some C++ compilers implement their own extensions to the language. In the case of Visual Studio, it defines Microsoft Extensions to C and C++ that can be turned off (Za) to be more ANSI compliant.
Visual Studio is actually notoriously late when it comes to supporting the C++ standard. Even now, some C++11 features are not part of the latest Visual Studio so keep this in mind when wondering why something you read in a book does not work in Visual C++.
One last note. Avoid using ATL and MFC if you try to be cross-platform compatible. Even if you don't want to be cross-platform compatible, ATL and MFC are only supported by Visual C++ and using them will lock you to using Visual Studio. Now with the Community Edition, both ATL/MFC are available for free if you are an independent developer or a small company, while historically, ATL/MFC were paid-version only as they are not part of Visual Studio Express editions.
It depends on which variant of Visual Studio you're using. If Express edition you want "for Desktop" in order to do ordinary standard C++. With full Visual Studio there's no problem.

Native C++ programs in Visual Studio

I'm confused in my understanding of the relationship between Visual Studio and .NET. I want to write a C++ application, but not a ".NET C++" application. By this, I mean that my understanding is that everything built in .NET land gets compiled to a CLI-compatible intermediary code (just like "JVM" languages like Java and Groovy compile to the same bytecode).
But I don't want my app compiled to an intermediary bytecode...I want it compiled down to raw binary!
Does Visual Studio do this? Or is .NET forced down my throat the minute I choose VS as my C++ IDE? If so, whats a "raw C++" alternative to VS?
Thanks in advance!
Visual Studio is an IDE, which is orthogonal to any specific language or compiler.
Visual C++ is a compiler that supports the C, C++, and C++/CLI languages.
In Visual Studio, create a Visual C++ project from one of the 'Win32' (as opposed to 'CLR') project templates and your program won't have any .NET dependency.
there is that /clr compiler switch when compiling a c++ app. Without it, you will get a pure native binary and cannot use any. NET specific features within your code.
By selecting a project template or by setting the corresponding project property, VS will automatically choose if the switch is on or off.
Visual Studio still supports 100% native C++ applications as will as managed applications. When creating a new app just choose the "Win32 Console Application" to create a native application. For existing applications you can change / verify by doing the following
Right Click on the project and select "Properties"
Navigate to Configuration Properties -> C/C++
Make sure that "Common Language Runtime Support" is set to "No Common Language Runtime Support"