Windows Phone 7 and native C++/CLI - windows-phone-7

Microsoft recently released tools and documentation for its new Phone 7 platform, which to the dismay of those who have a big C++ codebase (like me) doesn't support native development anymore. Although I've found speculation about this decision being reversed, I doubt it. So I was thinking how viable would be to make this codebase available to Phone 7 by adapting it to compile under C++/CLI. Of course the user interface parts couldn't be ported, but I'm not sure about the rest. Anyone had a similar experience? I'm not talking about code that does heavy low-level stuff - but there's a quite frequent use of templates and smart pointers.

c++/cli can theoretically be used with WPF/Silverlight using the trick of replacing the C# generated from the XAML with a macro definition that can be used inside the main class in a code behind file. I worked out this technique but haven't had the motivation to take it beyond theory - I'm quite happy mixing languages.
As far as using c++/cli in a pure safe mode for your logic code, this may still not be possible but I'd love to hear how someone goes trying it now. Whilst researching it for Silverlight back in 2008 I found this daunting silverlight forum comment:
I just gave Silverlight&C++ it a try by compiling the MSIL from my C++ project into a Silverlight-compatible DLL. The good news: it works, and you can call this code from a Silverlight project. The bad news: The C++ compiler apparently uses MSIL instructions that Silverlight disallows.
So, if you try this, even with the simplest of programs, you'll almost immediately get the exception "Operation could destabilize the runtime." To me, this makes it seem less likely that we'll see Silverlight for C++ soon, as the compiler will need to behave quite a bit differently.

You can generate verifiable managed code in C++/CLI using the /clr:safe option. The problem is that most of your normal c++ code will not compile with that option.

C# is currently the only supported language for WinPhone7.
I fully expect that MS will add support for VB and C++/CLI in the future too, but don't expect to open up the native-code kimono anytime soon.
Native code just has too many issues to overcome, specifically around security, reliability, etc. Managed code is FAR easier to statically verify and FAR easier to control while running.
If you're upset about porting C++ code to C#, just be glad MS didn't force you to have to move to Objective-C ;)
From our own experience, the proces of porting well-written C++ to C# actually takes a lot less effort than one might at first expect. Sure, there's a learning curve, but you have that with any port. We actually got so much benefit from porting our core app and data engines to C# that we re-tooled our entire team to code in C# and port our C# back to C++ where necessary rather than the other way around! So far, we've only ported two modules back to C++ and call our C# code from our native code via interop instead.
Again, remember, WinPhone is a brand new platform using best of breed, highly-productive, next-generation development tools and platforms. It is not your father's WinMo.
If support for C++ is something you find to be crucially important, then make sure MS know - (respectfully and professionally) state your position in the MSDN forums and at developer events near you.
Update1: 2012-12-17:
While native C++ still isn't officially supported for Windows Phone 7, Windows Phone 8 now supports native C++ code so you can more easily port your existing C++ codebase(s) to Windows Phone 8 (as well as Windows 8 and Windows desktop apps).
While there isn't 100% compatibility between the Windows8/Phone8 platforms and API's right now, I expect the two platforms to become increasingly integrated over the next couple of releases.
This is especially true now that one of the key barriers to closer cooperation between Windows and other groups at Microsoft recently left the company ;)
Update2: 4/15/2014:
As per the recent announcements at //BUILD/ 2014, you can now start building "universal" apps in C++ & XAML, C#/VB & XAML or JavaScript & HTML that will run on Windows 8.1, Windows Phone 8.1 and Xbox One! For more details on building Windows Phone 8.1 Universal Apps, read this article.

The whole development idea is built on Silverlight. I think you can add your managed dll written in C++ without any problem to this Silverlight project, but it could not use native code.
I am planning to install the tools on my machine tonight and will try this out.

It is fine if MS decides to leave the path and create something new, that is MS' decision. So let's face the facts. Silverlight is no success yet. MS lost significant share due to Apple, Android and RIM. Application developers simply have to evaluate the business case for their own applications and decide if they trust in a share gain of Windows 7 phone or not. For the company that I run, we decided not to support any more MS Windows phone 7, not because of this or the other technical reason, but just because that we don't believe in the return of our investment for the port.
We start supporting Apple, Symbian, Andoid and MeeGo in the future if we see a market success of this new platform. All support C/C++ and enable us to reuse our proven application cores. So why worry at all. Personal technology preferences should not be gating. If personal preferences worry, then I would kick MS out for their to me ugly looking UI.
Thomas

It is on the horizon finally!
So a survey sent to windows phone developers about their future
development preferences and XNA isn't mentioned once in the Survey (A
survey sent to windows phone developers - did I mention that)
They do however ask:
How would you prefer to use C++ in your mobile apps/games?
Develop apps/games that are C++ from top to bottom (UI, business logic, and platform
APIs)
Use C++ for business logic and then write platform abstraction layer
Use C++ for business logic use 3rd party runtime engines
I don’t want to use C++

Related

Options to write Win32 GUI applications?

As SO returns "4,476 search results for posts containing "win32 gui applications""... I'll have to ask a question that has probably been asked before but is lost in the midst of all those questions.
Currently, what are the options to write GUI applications for Win32, that have a big-enough following so that the environment offers enough and well-supported third-party tools?
I could come up with:
C++
Delphi, and possibly
RealBasic (although the fact that it's originally a Macintosh tool could result in small but noticeable issues in look 'n feel).
Besides their relative lack of well-supported third-party tools, solutions like Python + wxWidgets, or [Power|Pure|Free]Basic aren't good options: The former has too many 1.0 widgets (couldn't find a business-grade grid, for instance), and the latter are procedural languages so requires writing apps like Petzold's book with the lower productivity it entails.
Are there other solutions available?
Thank you.
Edit: Sorry for not having been precise enough: Big tools like .Net and Java are not options. I'm looking for tools that can either build a whole EXE statically (eg. Delphi) or provide a light enough runtime (VBClassic).
If you are new to programming I would suggest C# as well if you are only looking to make this app for the Windows Platform however with tools like Mono it can be ported to OS X and Linux Platforms.
Windows has their own IDE just for this called Visual Studio Express C#
Visual Studio's C#
As well as a version for C++ if you are wanting to say in that programming language.
The Mono project allows you to use C# in Linux and Mac as well as port the apps to iOS and Android
http://www.mono-project.com/Main_Page
You Can use C++ or You can even use the .net framework to develop your windows applications. .Net framework have lots of opensource contributed modules and paid modules and well as number of resources all over the internet to speed up the development compare to other options you have mentioned.
If you are going for a windows 32 gui application, I would prefer to go with .net framework, C++.
Java Swings also another best options which is platform independent as well.
You can use Lazarus as a free alternative to Delphi. Potentially you will have a very high possibility to check its "write once, compile anywhere" motto if you later decide to port your Win32 application to Linux or MacOS. In ideal case it will just work, but in reality you would probably need some conditional defines sections.

What's the main developing framework for the next Windows?

Some articles point to Windows 8 development being HTML-based instead of primarily using native code like C or C++ (as it has been until now) or .NET (as now, or even more so as it would have been in Longhorn, but never was.)
Is this true? Will the core APIs be accessible from Javascript then? What is the primary API / framework for Windows 8?
This is worth asking. When Windows 8 was demonstrated in June, a couple of comments by the presenter scared quite a few developers - or at least turned the Internet into panic mode. I'm surprised this question hasn't been asked here before.
The best article on the topic I have found is Windows 8 for Software Developers on Ars Technica.
The short answer is: it will remain the same.
The long answer is: it will remain the same, but several things will be added. You may want to pursue using those if you're willing to bet on new Microsoft technologies. One particularly interesting one is WinRT, which is a new object-oriented native code API exposed through COM, which is supposed to be a new version of the old flat Win32 API. Details are in the linked article.
It is very, very, very, very unlikely that anything that already exists, especially based on Win32 or .Net, would be removed. That means your existing programs written in .Net or native C++ or Delphi will continue to work fine. It is also unlikely that the primary development platform will be HTML. More likely is that HTML applications will be encourage for specific scenarios - perhaps touchscreen, kiosks and tablets.
I'd encourage you to read the article I linked to above - it covers this in far more detail than any answer here can.
There are three ways to develop for Windows 8, and they all access the same underlying API, the Windows Runtime.
Use C++ and call WinRT functions much like calling Win32 APIs back in the day (you know, yesterday)
Use C# or VB and call what appear to be .NET methods (but aren't)
Use Javascript and call WinRT functions
The UI is built with XAML using a pretty reasonable designer. More details are still coming out: check http://channel9.msdn.com/Events/BUILD/BUILD2011 for videos with detailed coding demos. http://channel9.msdn.com/Events/BUILD/BUILD2011/BPS-1005 is not a bad starting point.
There are 3 language/framework combinations that are all equally supported:
C++ and XAML
C#/VB and XAML
JavaScript and CSS/HTML
All are first class ways to write Windows 8 Metro style applications. Windows Runtime provides direct access to each of these languages and so choice of development environment can be based on familiarity or feature set of the language and not on restricted availability.
Update: I forgot one: C++/Direct3D (for games).
The original quote, in the context of writing a tablet desktop weather gadget application, is that the application uses "our new developer platform, which is, uhh, it's based on HTML5 and JavaScript."
The demonstrator never said a gadget is the preferred type for applications (How many Vista sidebar gadget or Windows 7 desktop gadget have you written in your life? Even when you can write them in simple HTML!), or the platform is the preferred platform for desktop weather gadget applications (How many animation control have you add to your application with video playing requirement? It is THE control used by Windows Explorer to display video!).
Today, after spending a few minutes playing with Windows 8 developer preview, I found that you can use Expression Blend 5 to easily auto-generate metro-styled applications in HTML and Javascript. Also in Visual Studio you can create exactly looking applications in Silverlight. :)
I am very excited!!! Go Windows 8! :)

MS Windows Programming advice for Mac/Unix developer

I have a few years of experience writing Unix command line tools (no GUI experience) in python, C and C++, and only recently crossed into the GUI world (Cocoa and IOS only). I've learned quite a bit of objective-C and am getting to understand how cocoa MVC works. However, one of the apps I am developing needs a Windows version and I was wondering what a good place to start would be given that I have absolutely no Windows development experience.
I was thinking about using Visual C++ 2010 Express as my development platform (because it's free and because I don't need to learn C++). My application is relatively simple, it will have only two windows and spend most of the time running in the background. It will however need to communicate with the OS (load dll's etc) and an online server (HTTP methods) and I'm not sure whether Visual C++ Express edition gives me access to the required API's. Would a Windows Forms application suffice? Am I going about this the wrong way? Do I need to learn C#? Any advice will be appreciated.
If you are already happy with proper c++, visual Studio C++ express should suit you fine. Given that you are not making a complicated GUI, you don't even need to dip into the managed code - C++ express allows you to create proper c++ console and GUI apps. You also don't need to install the platform SDK - it is part of VS C++ express.
Not being managed C++, you will be able to share source files between your various projects. managed c++, despite the c++ in the name, really is a different enough language that it will be annoying to work with if you simultaneously have to deal with iso C++.
--
Note: The native windows API is a C api, not a C++ framework. So it does not provide a rich set of classes in a coherent framework to deal with. On the other hand, while, large, it is actually quite simple to work with.
Also: Given that you are already familiar with Mac development, there is a LGPL (iirc) package called CFLite that builds on windows and that implements the C api that underlays the Objective-C Cocoa API.
If you use its abstratcions you can share a greater part of code between windows and Mac (and other platforms).
Other C++ IDE's you might want to consider:
Code::Blocks
QT Creator
both of which can be configured to use the MINGW port of GCC to windows.
you'll be better off with c++ than c# if you need more "low-level" stuff. Loading dlls (that is, libs) is simple (pragma comment lib...), as is pure HTTP transfer and communication.
So, VC++ with windows form will suffice, and it is "very c++".
You have access to all global APIs, and loading specific apis like http requires only two lines: one to include wininet header, and other lib (libs are actually "references" to dlls).
If you go the C++ Express way then you need to install Windows SDK separately, and set it up for Visual Studio to use it. And you can't use MFC.
I would however, suggest C#, because it feels like putting little toy bricks together. Easier to debug and maintain. Problem with C# is that it has so many library functions that you can not possibly know if what you want is already made to a function. But that's why we are here :-) If you feel that something you want to do should already exist then ask a question about it. One notable feature that C# lacks is zip archives (it has something similar, but not quite). For zips you can use public libraries, like SharpZipLib or DotNetZip.
If I were you, I wouldn't jump into a whole new API so quickly. Have you considered using Python on Windows? Most of the Python packages I've seen are also available for Windows, so you'll feel at home. And if you need some GUI, you can opt for wxPython, pyGTK or something similar.
For Windows specific things, you can always use ctypes. Especially if they're as simple as loading a DLL.
have you considered approaching Adobe AIR? it allows you to deploy on Mac, Linux, Windows, iOS, etc. communicating with and launching native processes has been possible since 2.0 and the the latest 2.5 SDK can target Android OS and TVs. with your experience you should be able to pick up ActionScript3 / MXML in no time.
additionally, there are a handful of free IDEs you can use with the Flex and AIR SDKs. or, if you're a student or low-income developer, you can get a free copy of Flash Builder 4 from Adobe: http://www.adobe.com/devnet-archive/flex/free/
edit: i believe deploying AIR applications on iPhone requires Flash Professional CS5, which includes the packager for iPhone options. at the same time, i've read that AIR and other cross-compilers for iOS are painfully slow, so it's perhaps best to develop natively in Objective-C for iOS.

Windows GUI Programming - C + SDK or C# + Windows Forms

I'm a C programmer with lots of server code experience (AIX, HPUX, some Linux) I need to write a GUI program for Windows (2000, XP, Vista, 7) which requires CAD-like drawing functions and lots of data entry forms (it's a specialised engineering app). I've written some Win32 code many years ago using Gupta SQLwindows (now Centura Builder). The bosses have decreed that it "must be" compiled code. My perception is that C+SDK could do the job but with considerable effort and that C# + Windows Forms would be more capable, but I'm a bit concerned about the .Net framework requirement.
Based upon your experiences, What would you suggest?
If .Net, which version? 2.0, 3.0, 3.5 ??
I'm not familiar with Centura Builder, so I am not sure at what level of abstraction your prior Windows programming experience is. If you choose the native code route using C/C++ and Win32, be sure to buy a copy of Programming Windows by Charles Petzold. Reading the first few chapters of this book can help you decide if you want to go the native code route as well.
If you choose the .NET Framework and C#, and if you do not need the version 3.5-specific features (such as LINQ for database access), I recommend choosing version 3.0. It is a built-in component on Windows Vista, so you don't have to package the runtime with your program installer unless you have to support Windows XP (which you probably do, so never mind :). With version 3.0, you get Windows Presentation Foundation (to use instead of or along with Windows Forms), which gives you a lot of graphical capability without a lot of effort. I'm not knowledgeable about CAD, so I don't know if WPF would provide the drawing functions that you need, but it may provide a great platform upon which you can write your own drawing routines.
EDIT: I missed your Windows version requirements on first reading, particularly the Windows 2000 requirement. I guess you'd have to go with .NET Framework version 2.0 and Windows Forms. I have to ask, though: Wouldn't it be cost-effective to improve your engineers' productivity by upgrading their eight-year-old machines to something newer and faster and therefore get rid of your Windows 2000 support requirement?
If you're going the .NET route, you will have to use .NET 2.0 because .NET 3.0 and above is only supported for Windows XP and above (Vista, 7, 2003, 2008).
I personally wouldn't sweat the .NET framework requirement. It's a one time install on each machine, that can be streamlined through Windows updates if needed.
If you don't want .NET, Qt + C++ is definitely the way to go; it certainly beats C and Win32. .NET still allows much faster development than even Qt though. Qt has the advantage of being fast and easy to deploy (no .NET requirement), and makes portability much easier (if you want to port to Linux or Mac).
If you must use native code then I would strongly suggest RAD Studio from Codegear / Embarcadero, it's a studio product that ships with Delphi (the object oriented language that evolved from Turbo Pascal) and C++ Builder, if you are already familiar with C/C++ then it's going to be very simple for you to pick it up. The Visual Component Library that is shared by both languages is extendable, powerful and RAD.
If you are able to use Managed code, then C# with Winforms is easy to use, WPF may be a better UI choice long term, but it has a steeper learning curve.
Depending on the complexity requirements of the CAD-like drawing, I'd go with C# + Windows Forms, or even more preferrably, C# + WPF.
WPF would make the drawing much, much cleaner than trying to do it in GDI. This is especially true if you're going to do some 3D "drawing", as you can do a lot of (simple) 3D objects directly in WPF. C# will make your GUI programming much more productive than trying to do it in C/C++ with the windows API directly (or even MFC).
Personally, the .NET requirement is minimal in my opinion, but that's really up to the powers that be in your organization...
If it must be compiled code than I would recommend WTL of MFC but it would be much more faster (in terms of develeopment cost) to use C# + WinForms or WPF.
You can do everything with C or C++ / Win32 api
(Win32 samples for CAD-like drawing are in MSDN..)

Windows programming: where to start?

I'm a long time Mac user, with a fair bit of programming experience and I wanted to try programming for windows. The thing is I don't know where to start, what should I learn first ? .Net, Win32 ?
[Clarification]: My ultimate goal would be to create a more or less complex application using the latest APIs however I like to know the underpinning of what I'm dealling with.
Start with the Bible, Programming Windows 5th Edition. It is still very relevant.
http://www.charlespetzold.com/pw5/
You'll start doing C with Win32. Once you understand that you can also learn .NET. Though some people may tell you to skip Win32 and go straight to .NET. However, doing Win32, you will understand a great deal about how Windows actually works.
I'd be taking a look at getting a copy of one of the Visual Studio Express Editions and start there. It has all the tools you need to build windows / web applications on windows.
You could start at the win32 level however depending on what exactly you want to do, you may find you're able to do everything you need with .net and visual studio.
Once you're finished with the suggested windows programming bible start reading The Old New Thing, Raymond Chen's blog.
There's a lot of interesting insight about inner workings of windows, why it is the way it is etc.
For rapid application development on windows, .NET seems to be the most efficient solution nowadays. But If you crave that extra ounce of performance out of your applications, I'd recommend giving Programming Windows and Windows via C/C++ a thorough read. Although some of the material is dated, a lot of it is still relevant with windows programming today. If you choose the .NET route some books to take a look at include Illustrated C# 2008, Accelerated C# 2008, and of course our own Jon Skeet's C# in Depth.
.Net is easier.
My ultimate goal would be to create a more or less complex application using the latest APIs
The latest APIs are .Net (Win32 is older).
however I like to know the underpinning of what I'm dealling with.
Win32 underpins .Net (although you might barely see Win32 artefacts when you're programming in the .Net environment ... for example the Mono project more-or-less-successfully ports the .Net API to non-windows).
Read the Petzold and see the Advanced Win32 api newsgroup for all undocumented stuff news://comp.os.ms-windows.programmer.win32 (source code for all Win32 apis...)
I'd recommend starting to program in .NET (C# or any other .NET language) since that's the most modern general application platform for Microsoft. I personally like the Richter books, CLR via C# and Applied Microsoft .NET Programming. Great starting points even though the 2nd book is a bit old and doesn't contain newer .NET features.
To truly learn the Windows platform, I totally agree with Bobby's suggestion to read Petzold's Programming Windows.

Resources