Windows forms application in VS2010 WITHOUT .NET? - c++

I want to create more or less portable (stand-alone, no install, WinXP to Win7) Win32 forms application in Visual Studio 2010. When I create a new project, it appears that the only way I can do it is if I use .NET/CLR, which makes me think it will be very unportable.
What is the preferred way of creating such apps?

Depending on what you mean with portable. An .NET application will function on all versions of Windows that runs the correct version of .NET (even other OS'ses in some cases http://www.mono-project.com/Main_Page). You will only have a dependency of a hudge framework, that I think most people running Windows have by now.
Besides .NET you have other alternatives such as MFC or native Win32 API.

you can either use C/C++ with MFC in VS 2010 or use something different altogehter creating a "native application" like C++ Builder or Delphi.
On the other hand .NET is installed by default in Windows XP SP3 and up - at least .NET 2.0 is always available... see http://en.wikipedia.org/wiki/.NET_Framework#Versions.

You can use .NET in conjunction with a linker (example 1 and 2) if you don't mind large executable sizes.
Otherwise, C/C++ without managed extensions.

Related

Running .net based exe application without .NET Framework

I just created a clr c++ aplication that combine c++ code and windows form
as resoalt the exe prodused from visual studio cannot use /mt and its not standalone (it require the wright .net installed on the computer)
are there ANY way to make a fully standalone exe from clr c++ exe?
i tried to check out spoon studio and Cameyo but it's look like they work only on files that includes instalation ...
The point is what a standalone application would buy you here? There is no such thing as a "standalone application" anyway - depending on how hard you look at it. You'll always have dependencies at least on the Windows version you intent your application to run on.
In the end it boils down to deployment or distribution issues. If you don't want your users to install a (newer) version of the .NET framework just to run your application, then start by determining the lowest Windows version you want to support with your application. Then check here for the .NET version that comes preinstalled with that version of windows. Then target your application against that version of .NET.

XAML apps using C++/CX for Desktop Windows

I have experimented with XAML UI programming using C++ for Windows 8 Store apps. I really like the developer experience, the XAML designer and the fact that I can get pure native apps with a modern rich user interface and high performance.
I want to create similar XAML apps using C++ for Desktop Windows (the non-Store world). How do I do this? For years I have waited for a native UI stack for Windows Desktop which is newer than MFC and somewhat higher level than direct Win32/GDI programming.
Both Silverlight and WPF use XAML along with code-behind to implement apps. Neither are still maintained but if you want to play with the same technology, it's there.
As Jeff McClintock mentioned, Microsoft has announced that a future update to Windows 8 will allow apps to run on the desktop, but I expect that this will merely be a windowing change and the apps will still run in the restricted sandbox that Store Apps run within. Maybe Microsoft will introduce yet another desktop-based UI framework and support it for three years before killing it.
WTL is newer than MFC, although its last update was six years ago. I personally recommend Qt, as it allows access to native Win32 calls (so you can do whatever ganky stuff Win32 apps normally want to do) while still having a rich, robust UI framework to build upon.
A future update to Windows 8.1 will allow Windows 8 Store Apps to run in a Window on the Desktop, and appear on the taskbar like a Win32 Application. This allows Store apps to Act a lot like Desktop Apps. MS have hinted store-app XMAL will be available to Desktop apps at some point in future.
http://www.gottabemobile.com/2014/04/02/microsoft-listens-to-users-start-menu-and-windowed-apps-are-on-the-way/
Codejock has some markup language support in MFC (native C++).
http://www.codejock.com/inc/img/downloads/samples/toolkitpro_markupsample_full.png
What I am looking at is C++/WinRT for native C++ applications that use the WinRT framework for UWP apps, at least for Windows 10. See C++/WinRT in the Microsoft Dev Center for a starting place.
C++/WinRT is an entirely standard modern C++17 language projection for
Windows Runtime (WinRT) APIs, implemented as a header-file-based
library, and designed to provide you with first-class access to the
modern Windows API. With C++/WinRT, you can author and consume Windows
Runtime APIs using any standards-compliant C++17 compiler. The Windows
SDK includes C++/WinRT; it was introduced in version 10.0.17134.0
(Windows 10, version 1803).
The intro article in the series goes on to say:
For authoring and consuming Windows Runtime APIs using C++, there is
C++/WinRT. This is Microsoft's recommended replacement for the Windows
Runtime C++ Template Library (WRL) and C++/CX.
I first got started with UWP apps for Windows 10 using C++/CX which uses the Microsoft Visual Studio C++ extensions with ref and all of the C# like extensions for C++ in a .NET world.
I am now working with Visual Studio 2017 and the C++/WinRT framework which uses native C++17 features along with an SDK. I believe you can also use C++/WinRT with Visual Studio 2015 with the latest updates, update 3.
There is also a package available from Extensions and Updates within Visual Studio, C++/WinRT, which contains a couple of Visual Studio templates for a couple of different application types.
C++/WinRT seems to be a work in progress. It seems best if you are using Visual Studio 2017 with the latest Windows 10, Version 1803, which contains the SDK and the XAML editor works fine. I have had problems with the XAML editor with an earlier build of Windows 10 Enterprise at work (IT Services maintains its own update servers and is a couple of builds behind the bleeding edge).
See also my question synchronizing SDK with Windows 10 update and using WinRT with Standard C++ which has an updated version of a test program from this article, C++ - Introducing C++/WinRT.

How to run C++ executable in Windows PE?

I have an executable I made using a CLI console application with Visual Basic 2010. I can run the program completely fine from my developer machine.
However, when I copy the executable over to another machine, re-boot to a pre-installation environment and run the executable again, nothing happens at all. There are no errors shown or anything.
My guess is the executable can't run without certain dependencies that aren't loaded at this environment, but I need it to work in a PE.
Any ideas on whats going on?
First of all, since the question is tagged "c++" and you mention C++/CLI several times, I assume that "Visual Basic 2010" is a typo for "Visual Studio 2010". But either way, whether you've written the application in Visual Basic (VB.NET) or C++/CLI, the problem is exactly the same.
My guess is the executable can't run without certain dependencies that aren't loaded at this environment, but I need it to work in a PE.
That's exactly correct. You've written an application that targets the .NET Framework. Somewhat like Java applications requiring a JVM, .NET applications require that the .NET Framework be installed in order to run (or a compatible alternative implementation, like Mono). Unfortunately, Windows PE does not support the .NET Framework.
Note that it is irrelevant whether you've written a WinForms, WPF, or Console application. Although they present their UI in very different ways, they all depend on the .NET Framework being installed.
You will need to (re-)write the application in a different programming language, one that generates native code without any dependencies on the .NET Framework. C and C++ are popular choices. If you choose to use C++, make sure that you create what Visual Studio calls a "Win32" project. This is one that targets the underlying operating system APIs directly (i.e. a native application) and does not have a dependency on the .NET Framework. Stay away from anything that has ".NET" or "CLR" in its description.
I don't really have a full comprehension of when an application is using .NET or not... I am just used to Linux C/C++ development. I hate Microsoft shit
It uses .NET whenever you use the .NET Framework libraries/classes in your code. I'm not really sure why this is so difficult to understand. The same problem could easily exist on Linux if you were using a third-party library that was not available in certain environments for whatever reason. This is not Microsoft's problem, it's an issue of using the wrong tools for the job. The .NET Framework is an object-oriented wrapper around the native APIs that makes it much easier for people to get up and running writing programs for Windows. But if you're "used to Linux C/C++ development", you should have little trouble writing a simple console application that targets the native APIs directly without using .NET.
If your hatred for "Microsoft shit" has turned into an allergy, you can avoid Visual Studio entirely and download MinGW, which is a Windows port of the GCC compiler you're probably used to. Combined with your favorite Windows port of Vi, you're working in an environment very similar to the one you're used to. And since GCC doesn't support C++/CLI or the .NET Framework, you won't have to worry about getting stuck picking the wrong option.
The .Net framework has been supported as an optional package install during your PE build process for the past couple versions of WinPE. I write code in C# that I run in WinPE everyday. I have yet to find a good way to debug in a manner where I can walk through break points, etc... though. My best option has just been a lot of logging and a global Exception catch around my main entry point that will write out a full stack dump. You can attach to your app as a remote process in a VM running WinPE, but if you need to catch something early in the execution you'll have a difficult time.

Best way to create a standalone-exe (Forms) (C++)

I have to create an application for testing that is relatively simple. If a user plugs in a device into a USB (hid library), the form will say "Pass". If no device is detected, it will say "Fail".
I want to create the app to run on WinXP+. It must be a forms application as it needs to be visual and have colors. The biggest requirement for me is that it must be stand-alone (a user just double clicks, the file and it opens, no installation). I need to avoid installing any extra .dll files and want to avoid the .net framework all together. It has to be written in C++.
So my question is, what are my options? I am new to Forms applications and the only forms application I have written required the .net framework.
From my research, Visual C++ seems out of the question as it requires .net for Forms apps. What about Turbo C++ by Borland? It seems outdated, but can it do the job?
I would suggest Borland C++ Builder 5 or 6. Visual C++ lacks the functionality to create C++ form apps, if we dismiss MFC
I'd say Visual C++ would probably still be your best option. A standard simple Win32 C/C++ program using only the native API will should suite your needs just fine. If you're targeting XP+, then the only dependency would be "msvcrt.dll" which is included with Windows by default.
Edit: This article on MSDN should get you started in the right direction.
What you're talking about is C++/CLI, it's microsoft's dialect of C++ that requires a .Net framework. Please distinguish it from real (native) C++, which can be used to create what you want to. Visual C++ is perfectly fine, just make sure you don't create a .Net project.
Forms are a .NET library. It's not Windows or anything like that, you can use the native GUI libraries in Win32 with no problem or any native wrapping of them. You can implement this in native C++ easily in Visual Studio.
If you're looking to create the application in a rapid fashion (i.e. stock UI components that you can drag and drop onto forms), my experience is that Embarcardero C++ Builder effectively solves that problem space.
I like Visual C++ but it's not a great environment for rapidly creating forms based applications. I want to emphasize that I'm referring to Rapid Application Development (RAD) tools. There are plenty of great C++ IDEs and libraries for creating forms based applications and all of them should be able to create standalone exes.
Here is a list of related questions that might help in your decision:
https://stackoverflow.com/q/1754020/4916
https://stackoverflow.com/q/93326/4916
Best C++ IDE or Editor for Windows

Visual C++ 2010 and Native executable file

Native exe!
that means my program can run easily without any requirement?
even if I use .net classes?
You know I want to write a program that is so light and I don't like to use C# or any other .net programing language because all of them need .net-framework 4.5.
Just think a 2.5 MB programm needs a +250 MB .netframework.
New Update - 12/01/2016:
It's almost 4 years ago when I asked this question. As you know Dotnet Native is announced. It's an interesting feature which compile IL into native code.
Compiling Apps with .NET Native
.NET Native is a precompilation technology for building and deploying
Windows apps that is included with Visual Studio 2015. It
automatically compiles the release version of apps that are written in
managed code (C# or Visual Basic) and that target the .NET Framework
and Windows 10 to native code. Typically, apps that target the .NET
Framework are compiled to intermediate language (IL). At run time, the
just-in-time (JIT) compiler translates the IL to native code. In
contrast, .NET Native compiles Windows apps directly to native code.
For developers, this means:
Your apps will provide the superior performance of native code.
You can continue to program in C# or Visual Basic.
You can continue to take advantage of the resources provided by the .NET Framework, including its class library, automatic memory
management and garbage collection, and exception handling.
Last I checked none of the .NET frameworks were 250+ MB! Yes, the offline installer for .NET Framework 3.5 SP1 is 231MB but it contains x86 and x64 versions of .NET 2, 3 and 3.5 sp1.
You should read this http://www.smallestdotnet.com for details on sizes of various versions of the installers.
Now on to your question:
Yes, It is a little annoying to have your clients install a big framework, even 20-40MB does get annoying. With .NET, the advantage is the ease of programming (In my opionion) compared to other Native options.
Your native options are:
MFC - You need only the VS runtimes installed, which is 1-2MB and is usually installed on newer pcs. Also, you can ship your application with the MFC libraries packaged into a dll which is again <2MB
The trade of here is you need to program in C++, the libraries overall are a very thin layer over the native libraries. and people have had harsh opinions about MFC. I've barely just tried it.
Win32 API - This is going all bare bones, and quite difficult, you could use C or C++ but you'd really have to know a lot about the Win32 API and how windows itself works (Stuff like windows messages, hwnds etc) Its not fun, believe me. But during deployment you would not need any external libraries.
There are tons more options, see here:
Native Windows Application Development Options
https://stackoverflow.com/questions/2711599/what-programming-language-should-i-use-to-create-small-native-windows-applicatio
Here are some links on MFC that might help:
Want to learn Windows Programming,some suggestions?
How do I decide whether to use ATL, MFC, Win32 or CLR for a new C++ project?
C++ MFC vs .NET?
https://stackoverflow.com/questions/557114/stick-with-mfc-or-go-to-net
you are able to create native exe by using c++ Win 32 projects.
Alas, nearly everything requires a download runtime library and even if you have one installed, you'll need to download updates for them almost continually. Even Microsoft C++ apps nowadays come with security updates that have to be installed if you've compiled your app with them.
But.. there is a solution of sorts. If you use C++, it has a feature where only the things you use are compiled into the final app. Normally, this would require linking with all the library dlls, but if you statically link with the library, you will end up with a single .exe that is as small as can be, and you will not need any dlls (as all the code contained in the library will be compiled into the .exe).
The benefits are debatable compared to dlls, but as MS has pretty much broken the idea of shared dlls in .NET (ie, you practically have to put all the shared dlls in the same directory as your running app, giving you a nightmare in maintenance if you have these shared dlls spread around all your apps) then there's not much of a difference anymore. Static linking is getting a little bit of a comeback and sounds like its what you want.
For modern C++ development, you'll probably want to take a look at Qt instead of MFC. Its a lot nicer to use and is cross-platform so you can run Qt apps on your Android or Linux platforms as well as Windows.