views:

346

answers:

5

While doing Windows Mobile development, which language should I use? C# or C++ or something else? Why one is better than others?

+4  A: 

Hi,

It depends what you're coding.

Making native calls to the OS are possible via P/Invoke from C#, but extensive use is probably easier via native C++. You'll also require C++ for using some hardware that has not been wrapped by the Compact Framework.

Most hardware (GPS, camera, etc.), is available via CF. If you're working with a Win Mobile 6.x device, you're probably better off with C#. In addition to hardware, Pocket Office's (POOM) object model is also available to C#, so you can integrate with it.

It's worth noting that most references to Windows Phone 7 refer to managed code and the possibility of Silverlight. With Silverlight in the mix, you'll have to code with C#.

Unless your app is high performance or is extremely miserly with memory, use C# or VB.NET.

Scott

Scott Davies
Just as a side not, Silverlight doesn't necessarily mean C#. For example CE 6.0R3 has a full "Silverlight" XAML engine, and it's only usable from C++.
ctacke
That's correct - Silverlight can be coded with VB.NET, but it can't be targeted with C++, so in this case, going with C# is the answer. The Silverlight implementation for Win CE 6.x is quite cool, but Win Mobile is a different build of CE and currently does not have a Silverlight implementation.
Scott Davies
My point is that we don't know if WinPhone's Silverlight, if it has it, will be managed or C++ based. We can't discount that it may be C++ because there's a precedent already set for CE that Silverlight is done in C++.
ctacke
It appears, from the small amount of info available, that native Windows Phone 7 Series development will be very limmited, and Silverlight and XNA will be the primary presentation layers, with Managed .NET code to do the heavy lifting.
Nate Bross
@ctacke: As far as I know, WP7 has nothing to do with Windows CE. It's a Zune more than it's a Windows Mobile.
jalf
@jalf: and what OS do you think it will be running underneath? Probably the same as Zune, yes? What OS do you think that is? Just because it doesn't look like the CE desktop you're used to doesn't mean they created yet another whole new OS.
ctacke
From what I read so far native API will be available in a limited way to OEM's only. Developers will do it using managed code. Read here for more: http://forum.xda-developers.com/showthread.php?t=634048There are some screen-shots of the documentation that was not yet released.
Shaihi
Thanks for the link to XDA; it's a great site. @jalf: see: http://en.wikipedia.org/wiki/Zune and look for the mention of the kernel being Win CE based. Win Mo 6.x phones are variants of the Win CE OS, but with different UI/features than a standard Win CE 6.x profile (i.e. Silverlight exists for Win CE 6.x but not for Win Mo 6.x).
Scott Davies
+1  A: 

It depends on task mainly.

c++ has following pros/cons:

  • Direct access to resources, faster programs
  • Can access very deep OS parts, not needed for high level applicaiton
  • harder to develop and requires to manage resources by developer

C#:

  • Runs under virtual machine (CLR), that's why is slower
  • Faster and easier application development
  • Rich build-in library
Andrey
+1  A: 

It depends.

At least present a specific use-case. And possibly use SO search? :)

http://stackoverflow.com/questions/708484/c-or-c-to-program-mobile-barcode-device

Edit: Apparently others were faster to the draw, and gave more articulated answers. Nevertheless, I still recommend reading the above SO thread.

pithyless
+1  A: 

There is no right answer for this, becasue there is no one-size-fits-all "better" definition. If you know C++ and have a lot of C++ code assets already, C++ sure looks appealing. If you know c# and not C++, then C# sure looks appealing.

C++ applications load faster, but for many applications, that's not relevent. C# applications can certainly be written faster, but they also don't have determinism. I'd never even attempt a UI in C++ any longer, nor would I think about doing database access in C++. I wouldn't write a driver in C# though, or a shell extension.

Generally speaking, most solutions I've ever delivered were a mix of the two. C# has its strengths. It's fast to write, easier to debug and unit test, hard (though not impossible) to create leaks and for some operations (like data access or XML parsing) it's just easier.

C++ has its strengths too, like speed of execution (though C# can be made to go just as fast for many things), determinism and the ability to plug in to things that want native entry points.

So my answer? You need to know both, and likely write your solutiuon using both. The percentage of each you end up using depends on what your end goal is.

ctacke
You may also find sticking with C# is useful in more mobile projects - Mono Touch (http://monotouch.net/) lets you write iPhone apps in C# and they are planning on a release for targeting Android phones (called Mono Droid), although Mono Droid has not been released yet. Staying with C# is easier than using C++, Objective-C and Java.
Scott Davies
Maybe in a theoretical world, but a vast amount of WinMo code in the CF is very CE secific, using Microsoft's WIndowsMobile namespace or P/Invoking to coredll. The availability for any sort of reuse there is quite minimal, and the UI elements are also vastly different. For those reasons, I wouldn't say that C# is any more portable across these platforms than C++.
ctacke
Core services of smartphones will definitely be unique, but I still think you have a better chance of leveraging C# 3.0 code across all three platforms. The UI specific stuff on the iPhone, for example, is wrapped via C#. Of course, those wrappers are different from Windows Phone GUI API's, but I think it's easier to stick with C# instead of learning Obj-C for the iPhone and Java for Android. Algorithms are not necessarily platform bound.
Scott Davies
A: 

From my experience it is easier to start with c#, and if the api provided by the compact framework is enough for you then you are ok.

On the other hand if your project is somewhat complex, or if you want to do something that is not in the compact framework you may end needing to create a helper .dll in c++. Even in this case you maybe good doing your main program in c#, and programming helpers dll in c++.

If you go directly to program in c++ you may benefit from the fact that you have a raw performance better than c#, which is good if you are doing a game.

But you will also suffer more from the limitation of windows mobile OS. Like a maximum of 32MB per process, or that all .dll share the same address space.

So in the end it really depends on what are planning to do and the experience you have.

Ismael