You are browsing the archive for How To.

How to post source code for highliting

12:20 pm in How To by buzz_lightyear

Here’s little howto about posting source code in your posts, here at buzzdev website.

Posting Source Code

While our site doesn’t allow you to use potentially dangerous code on your blog, there is a way to post source code for viewing. We have created a shortcode you can wrap around source code that preserves its formatting and even provides syntax highlighting for certain languages, like so:

#button {
font-weight: bold;
border: 2px solid #fff;
}

Wrap your code in these tags:
[sourcecode language='css']
your code here
[/sourcecode]

Any of the following can be used for the language parameter (using one is required):

  • bash
  • cpp
  • csharp
  • css
  • delphi
  • html
  • java
  • jscript
  • php
  • python
  • ruby
  • shell
  • sql
  • vb
  • xml

Code in between the [sourcecode] tags will automatically be encoded for display, you don’t need to worry about HTML entities or anything.

Other BBCode Methods

Find [sourcecode language='css']code here[/sourcecode] too long to type? Here’s some alternative examples:

[source language='css']code here[/source]
[code language='css']code here[/code]
[sourcecode lang='css']code here[/sourcecode]
[source lang='css']code here[/source]
[code lang='css']code here[/code]
[sourcecode='css']code here[/sourcecode]
[source='css']code here[/source]
[code='css']code here[/code]
[lang='css']code here[/lang]
[css]code here[/css] (or any of the supported language)

Note: Quotation marks around the language can be omitted for even shorter and neater syntax.

FAQ

I still see the BBCode in my post. What gives?
Make sure you correctly use the BBCode with a valid language attribute. A malformed usage of it won’t result in replacement.

I use the visual editor, my code has lots of line breaks inserted, what do I do?
Use ‘shift + return’ instead of ‘return’ when changing lines.

Getting started with widgets on Windows Mobile 6.5

11:41 am in How To, Software development, Windows Mobile by buzz_lightyear

Now that the Windows Mobile 6.5 resource kit is out (You can download it from here) it is time to start writing widgets!!!

Necessary equipment

  1. The 6.5 emulator images
  2. The web development environment of choice
  3. WMDC or Windows mobile device center (on vista or windows 7) or ActiveSync 4.5

With that you should be ready to go to get started, the first step is to start the emulator and cradle the device. The emulators can be started from the start menu under the “Windows Mobile 6 SDK -> Stand Alone Emulator Images -> ”. The device emulator manager can be started using explorer to navigate to the following folder “C:\Program Files\Microsoft Device Emulator\1.0” and selecting dvcemumanager.exe.

Once they are both started, open WMDC or ActiveSync and select connection options and, on the “Connect one of the following” combo box select “DMA” and click “OK”.

Now, on the “Device Emulator Manager” select “Refresh” and then find the emulator on the list, should be the GUID under others and right click -> cradle to connect it to the PC.

Once that is done, select “Connect without setting up my device” and you should be ready to go, to test, open internet explorer on the 6.5 emulator and navigate to any site, if all is set up correctly it will navigate to it using our brand new browser.

And now…. the fun part begins!

To write a widget we need to follow three easy steps.

Develop your widget code

For this you can use the web development tool of your choice, but as an example we can start with something super simple, as follows (write it into a widget.htm document)

code01

Package your widget

Now we have our extremely functional widget code, now we need to create a manifest file (so the framework knows what to do with it) following the w3C widget standard for packaging and configuration (On 6.5 we support the December 22 2008 draft), but to make things easy, here is a small manifest, copy it into a config.xml file in the same folder as your widget.htm

code02

Don’t forget to also add an icon called icon.png on the same folder.

At this point, you should have three files (config.xml, icon.png and widget.htm), now we need to package them, on explorer, select the files, right click and send to a compressed folder (it is important to select the files and not the folder that contains them because we want config.xml to be in the root of the zip container). Now just rename the newly created zip file to “widget.wgt” and you are done with this step.

Deploy and run

On “Computer” you should see the cradled device emulator as “PocketPC device”

Use it to navigate to “My Documents” on the device and copy the widget file created in step 2 there. Now, on the emulator, open file explorer using the start menu and, listed there you should see your widget file, click on it.

This should start the installation process, once that is done you will see your very first widget on screen!!!

To continue playing with this widget (make it better, etc) you can find the uncompressed files on the “Program Files\Widgets\User\ folder” on the device.

The widget ID is generated at install time and it is an always increasing integer (therefore, the most recently installed widget will have the greatest number). You can replace, add, remove files here for testing at will; the only thing you need for a your widget to pick the changes up is to exit it and start it again, it will have an entry on the start menu.

I will be sharing more information about the widget API, how to extend the widget framework capabilities, debugging tips, best practices, etc in future posts but I wanted to help everyone to get started.

For now, you can also take a quick look at my TechDays session where I describe the API set and some of the capabilities of the framework. To access it you’ll need to log into the Microsoft Tech Days site and search for MBL302 Windows Mobile Web and Widgets: Leveraging web technologies to build experiences for Windows Mobile.

Stay tuned, have fun and don’t forget to share your thoughts… Also, before I forget, you can upload your cool widget creations to the Marketplace :), visit http://developer.windowsmobile.com for more information.

Jorge Peraza

Say good bye to GAPI

11:38 am in How To, Software development, Windows Mobile by buzz_lightyear

The Games API (GAPI) was a technology that allowed Windows Mobile 2003 applications to quickly draw graphics onto the device screen. It also contained functions that allowed an application to request all button press messages, even the ones that were normally intercepted by the Windows Mobile operating system.

The graphics component of GAPI was replaced by DirectDraw (which allowed hardware acceleration) in Windows Mobile 5.0. Application compatibility was maintained so that older programs would still work.

Most of the reference material for GAPI was removed from the Windows Mobile 6.1 documentation set, although the input functions were kept, so that applications could still request all key and button presses.  Application compatibility was maintained for this release as well.

This is all changing for the next generation of Windows Mobile, Windows Mobile 6.5.  Although some devices may still support GAPI, there is no longer a requirement for device manufacturers or mobile operators to ship or test for compatibility with GAPI.  This means that applications that require GAPI will provide an unpredictable experience for users on Windows Mobile 6.5 devices.

Another important change is that acceptance to the Windows Marketplace for Mobile and Designed for Windows Mobile certification requires no application dependencies on GAPI.

In order to replace the input functionality that GAPI once provided, a new keyboard API function is being made public.  This function is AllKeys(), and is defined below.  One great thing about this substitution is that AllKeys has been a part of Windows Mobile as long as GAPI, and is actually the API call that GAPI wrapped in order to publicly expose this functionality. This means that the transition to AllKeys should be easy, and backwards compatibility should be maintained.

You can migrate your input code to AllKeys in the following way:

Replace:

  • GXOpenInput() with AllKeys(TRUE).
  • GXCloseInput() with AllKeys(FALSE).

While AllKeys is set to true, all key presses will be sent to your application for handling.

Since GXOpenInput and GXCloseInput were simply wrappers for a call to AllKeys, so this substitution should cause no change in behavior in your programs.

The following is the definition of the new AllKeys API.

AllKeys

This function allows your programs to request that all key presses be sent directly to the requesting application. Normally some buttons are intercepted by the operating system for its own use, but games and input – intensive applications may want access to these buttons for their own use.

Syntax

BOOL AllKeys(
BOOL bAllKeys
);

Parameters

ParameterDescription
bAllKeys[in] If bAllKeys is set to TRUE, this function allows all keyboard events to be sent to the application. (This includes the soft-key buttons and back button).

If it is set to FALSE, this function specifies standard keyboard event behavior. Some events including soft-key buttons and the back button are not sent to the application.

Return Value

Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.

Sample Code

The following C++ code illustrates how to use AllKeys. In the application that this sample is taken from, a check box is used to set AllKeys to true or false.

// process checkbox
case IDC_ALL_KEYS_CHECK_BOX:
if (g_AllKeys == true)
    {
    // Allow the OS to intercept some button presses
     AllKeys(FALSE);
    g_AllKeys = false;
    // set button state
    SendMessage(hwndCtl,BM_SETCHECK, BST_UNCHECKED,0);
    }
else
    {
    // Do not allow os to intercept button presses
    AllKeys(TRUE);
    g_AllKeys = true;
    //set button state
    SendMessage(hwndCtl,BM_SETCHECK, BST_CHECKED,0);
    }

Requirements

OS Versions: Windows Mobile 2003 and later.

Header: Winuser.h

How to start developing for Windows Mobile

9:33 am in How To, Software development, Windows Mobile by buzz_lightyear

Where to start?

It is safe to say that there are more options for development on Windows Mobile 6 than on any other mobile platform. WM has been around for a while, and Microsoft has built up a huge variety of APIs and development tools to support the platform. This is good – no matter what your preferred style of programming is, there is probably a supported solution on WM. It can also be confusing if you are trying to find out where to start when developing an application.

The options include:

  • Browser based development using scripting languages and Flash or Silverlight. This option is poorly supported in the existing mobile browsers, so at the moment, this is not a practical option.
  • Managed Code using . NET languages and the .NET Mobile Library.
  • Native coding using C++ and Windows Mobile native libraries.

Note: Not all Windows Mobile native libraries have managed equivalents. This means that the author of a managed program (in C# or VB for example) will have to use cumbersome and potentially unsafe methods to integrate the native library into the managed application if they wish to make use of the full libraries.

There are also different flavors of Windows Mobile 6: Standard and Professional. The big difference is that Professional devices have touch screens, and generally more features. It’s reasonable to expect that the performance of a professional device will be superior to that of a standard (no touch screen) device and the touch screen allows more input possibilities so I expect to focus on those devices.

At the moment, I’m not sure if I want to develop on managed or unmanaged code. I prefer to develop in C# using managed code, but may need the performance and APIs that are available to the C++ programmer. Luckily, I will use the same tools to develop both kinds of applications for WM, so I don’t have to decide what environment to use quite yet.

Reading up

In the past, the first stop in making sense of all these options would be to check Microsoft’s official documentation on MSDN, but that is changing. The official starting point for development on Windows Mobile is now the Windows Mobile Developer Portal.

For the moment, I actually prefer the material found on a different site -Windows Mobile Developer Center, although I’m told that these two sites will be integrated in the next few months. This site has webcasts, videos, and (of course) this blog.

The first thing I want to do is set up my development environment, and so I started looking for a section that would tell me how to start.  I already have a copy of Visual Studio 2008 installed, and wanted to use it, so I looked for that first.

Setting up

Note: Unlike the documentation on MSDN (Windows Mobile 6 Documentation) which only covers Visual Studio 2005, the information I found for setting up Visual Studio 2008 on the Developer Center was in videos. See http://code.msdn.microsoft.com/WM6YourFirstApp for a good getting started video.

Although the videos are current, excellent and accurate, watching the video is more time consuming than reading a procedure, (and impossible to find via search) so I’ll summarize them here:

  1. Install Visual Studio 2008. The SDK only works with the Standard and Professional editions, not with the free Express editions. There is a 90 day trial edition that you can download for free at the following web page: Try Visual Studio 2008 – Trial Software.
  2. Install the Visual Studio 2008 Service Pack 1 and .NET Framework 3.5 Service Pack 1. There may be other service packs available by the time you read this. Information on the latest service packs may be found at the following page: Visual Studio 2008 Development System.
  3. Download the Windows Mobile 6 SDKs from the following page: Mobile 6 Professional and Standard Software Development Kits Refresh. I am installing both, although I am planning on writing only for the Professional Edition device. You never know when you might change your mind!

Note: if you have installed the SDKs before Visual Studio 2008, you will need to remove and re-install them after the VS 2008 install.

Building a test application

To confirm that you have a working installation of Visual Studio and the SDK(s), try creating a simple application. I created a blank C++ project by following these steps:

  1. On the start page of Visual Studio 2008, in the upper left hand corner, there is a block titled “Recent Projects”. At the bottom of this block, there is a link for Opening a Project, and for Creating a Project. Choose Create Project.
  2. In the New Project dialog box, choose “Visual C++, then “Smart Device in the Project Types list. The Templates section should be populated with different project templates for different kinds of projects.
  3. Choose Win32 Smart Device Project, and enter a name for the project. “Test” is fine. Click OK.
  4. The Win32 Smart Device Project Wizard opens. The presets are set to Windows Mobile 5.0, which I don’t want to use, so I choose the Next button at the bottom of the dialog.
  5. This brings up a list of installed Windows Mobile SDKs. I am going to remove the Windows Mobile 5.0 SDK from the Selected SDKs list, and add the Windows Mobile6 Professional SDK and Windows Mobile Standard SDK. Once this is done, I click Next.
  6. In the Project Settings Dialog, I select “Windows application” and click Finish. The dialog closes, and Visual Studio creates a new project, populated with basic files, named “Test”.

In Visual Studio, I make sure that “Windows Mobile 6 Professional Emulator” is chosen in the drop down list on the upper left tool bar. I then build the application “Test”, and choose to start debugging.

The Emulator appears, and in a moment, my application (with a blank screen) loads and is displayed in the emulator.

emulator

Clicking on the close icon in the upper right hand corner shuts down my application, and Visual Studio returns to its default state.

Excellent – that was easy, and everything works!

If I wanted to build for a different flavor of Windows Mobile (Standard, Windows Mobile 5, or deploy to an actual device, I would choose a different option from the upper left hand tool bar drop down. Does it all make sense so far?

Delay loading of a service by adding a dependency

10:48 pm in How To by buzz_lightyear

Problem:

There are many occasions when we need to make an application, running as a service, load last to make sure that all dependent applications have loaded. For example, suppose you have an application that needs to connect to a database on load. That would mean that SQL server service must be loaded in order for your application to work as intended.

Solution:

Method 1

You can add a dependency to your application’s service so that it either loads later in the boot sequence. To do that:

Read the rest of this entry →

Connect to the console session on a Windows 2003 server

10:19 pm in How To by buzz_lightyear

I’ve come accross this many times: Not being able to connect to the console session on a server from a windows 2000 terminal services/RDP client. The problem was that the Windows 2000 client doesn’t recognize the /console switch. But Microsoft to the rescue… Problem is solved pretty simply using plain old command prompt:

mstsc -v:servername /F  -console

Actually this solution was in the KB Article: http://support.microsoft.com/kb/278845 which also provided great insight on how to shadow the console so that the person sitting in front of the psysical screen can see what you’re doing instead of the screen being locked (as it normally is).

Use a PPC Phone as a modem with another WM5 PPC

9:48 pm in How To by buzz_lightyear

Suppose you have a PDA like the HP iPAQ 2490/2790/214 and you want to use you HTC as a dialup modem (assuming your HTC does support DUN profile. If it doesn’t then you can install it using a cab file, but more on that later). In this example I will assume we are using an iPAQ with the WidcommSo here are the steps you need to follow: Read the rest of this entry →

"Data connection to printer lost" when priting on an HP 460 Bluetooth printer

9:00 pm in How To by buzz_lightyear

Symptom:

When using an HP 460 Bluetooth Printer (using a BT CF Card), and printing from your PPC, you get a connection error. These errors are random and cannot be reproduced. The error message is “Data connection to printer lost”

Solution:

This is a confirmed problem with PrintCE and the CF Card used by the printer (http://www.fieldsoftware.com/HP460error.htm). The only solution is to change the CF card and use a USB BT adapter on the printer. I’ve tried the LevelOne adapters and they worked fine for around 20 Euro. Of course you could always buy the HP adapter and pay over twice as much.

ActiveSync does not run on Windows 2003 SP2

8:51 pm in How To by buzz_lightyear

Symptom

The installation will finish correctly but when you try to run ActiveSync you get a message “Please wait while Configuring Microsoft ActiveSync” and program is stuck on that screen. Repair, uninstall, reinstall all fail.

Event Viewer Application Log shows two warnings:

Event Type: Warning
Event Source: MsiInstaller
Event Category: None
Event ID: 1004
Date: 31/1/2008
Time: 3:23:56 ??
User: SERVERAdministrator
Computer: SERVER
Description:
Detection of product '', feature 'ActiveSync', component '' failed. The resource 'HKEY_CURRENT_USERAppEventsSchemesApps
WcescommPegConnectConfirm.current' does not exist.

Event Type: Warning
Event Source: MsiInstaller
Event Category: None
Event ID: 1001
Date: 31/1/2008
Time: 3:23:56 ??
User: SERVERAdministrator
Computer: SERVER
Description:
Detection of product '', feature 'ActiveSync' failed during request for component ''

Solution

The first warning it the actual prize winner. The key mentioned is missing and that’s the cause of the problem. You will have to go into the registry, build the path by hand and then do a repair install (not necessary but recommended).

Can't copy files from PPC to PC using ActiveSync

8:42 pm in How To by buzz_lightyear

Symptom:

When you copy a file from your PPC to your PC using ActiveSync, the file appears to be copying but it never shows up in the folder you put it, it just “disappears”.

Solution:

ActiveSync copies the files in the user’s temp directory and then moves the file to the location you chose. Although the file does get copied over from the device, the actual move from the temp directory to the chosen location fails. To solve this, you need to register the Ole32.dll file.

  1. Start -> Run
  2. In the run box type:
    Regsvr32.exe %Windir%System32Ole32.dll
  3. Click OK