Monday, September 26, 2005

CF : Installing a cab file programmatically and quietly (no user interaction)

The trick is using wceload.exe with the /no­askdest and /noui parameters.

Again thanks to opennetcf.org.

private bool installCabFile ()
{
try
{
ProcessInfo pi = new ProcessInfo();
if (CreateProcess ("\\Windows\\wceload.exe","/no­askdest /noui " + downloadFileName, pi))
return false;
}

catch (Exception e)
{
Cursor.Current = Cursors.Default;
MessageBox.Show ("Problem installing Cab file " + e.ToString());
return true;
}

return false;
}

// CreateProcess PInvoke API
[DllImport("CoreDll.DLL", SetLastError=true)]
private extern static int CreateProcess ( String imageName, String cmdLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, Int32 boolInheritHandles, Int32 dwCreationFlags, IntPtr lpEnvironment, IntPtr lpszCurrentDir, byte [] si, ProcessInfo pi );

// GetLastError PInvoke API
[DllImport("CoreDll.dll")]
private extern static Int32
GetLastError();

public Int32 GetPInvokeError()
{
return GetLastError();
}

[DllImport("CoreDll.dll")]
private extern static Int32
WaitForSingleObject ( IntPtr Handle, Int32 Wait);

public bool CreateProcess (String ExeName, String CmdLine, ProcessInfo pi)
{
Int32 INFINITE;
unchecked {INFINITE = (int)0xFFFFFFFF;}
bool result = false;
if (pi == null) pi = new ProcessInfo ();
byte [] si = new byte [128];
result = CreateProcess (ExeName, CmdLine, IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, si, pi) != 0;
WaitForSingleObject (pi.hProcess,INFINITE);
return result;
}

public sealed class ProcessInfo
{
public IntPtr hProcess = IntPtr.Zero;
public IntPtr hThread = IntPtr.Zero; public int dwProcessID = 0;
public int dwThreadID = 0;
}

Enjoy!

(Compact Framework)

CF : Battery status in CF

bool success = GetSystemPowerStatusEx (ref system_power_status_ex, true);

this.lblMainInfo.Text = system_power_status_ex.BatteryLifePercent.ToString() +
"% Power Status " + (BatteryChargeStatusEnum)system_power_status_ex.BatteryFlag;

this.lblBackupInfo.Text = system_power_status_ex.BackupBatteryLifePercent.ToString() +
"% Power Status " + (BatteryChargeStatusEnum)system_power_status_ex.BatteryFlag;

where:

[DllImport("Coredll.dll")]
public static extern bool GetSystemPowerStatusEx(ref SYSTEM_POWER_STATUS_EX pstatus, bool fUpdate);

[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_POWER_STATUS_EX
{
public byte ACLineStatus;
public byte BatteryFlag;
public byte BatteryLifePercent;
public byte Reserved1;
public uint BatteryLifeTime;
public uint BatteryFullLifeTime;
public byte Reserved2;
public byte BackupBatteryFlag;
public byte BackupBatteryLifePercent;
public byte Reserved3;
public uint BackupBatteryLifeTime;
public uint BackupBatteryFullLifeTime;
}

private SYSTEM_POWER_STATUS_EX system_power_status_ex;

public enum BatteryChargeStatusEnum : byte
{
High = 1,
Low = 2,
Critical = 4,
Charging = 8,
NoSystemBattery = 128,
Unknown = 255
}

Thanks to the good folks at OpenNETCF (see "Links") for this.

Enjoy!

(Compact Framework)

CF : Hiding / showing the taskbar in CF

This is for Windows CE Compact Framework.

In the "onLoad" method:

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

To show:

int h = FindWindow ("HHTaskBar", "");
ShowWindow (h, SW_SHOW);
Rectangle rc = this.Bounds;
this.Capture = true;
IntPtr hwnd = GetCapture();
this.Capture = false;
MoveWindow (hwnd, rc.Left, rc.Top, rc.Right, rc.Bottom - taskBarSize, true);

To hide:

int h = FindWindow ("HHTaskBar", "");
ShowWindow (h, SW_HIDE);
Rectangle rc = this.Bounds;
this.Capture = true;
IntPtr hwnd = GetCapture();
this.Capture = false;
MoveWindow (hwnd, rc.Left, rc.Top, rc.Right, rc.Bottom + taskBarSize, true);

where:

private int taskBarSize = 24;

const int SW_HIDE = 0x0000;
const int SW_SHOW = 0x0001;

[DllImport("coredll")]
public static extern IntPtr GetCapture();

[DllImport("coredll.dll")]
public static extern int FindWindow (string lpClassName, string
lpWindowName);

[DllImport("coredll.dll")]
public static extern int ShowWindow (int hwnd, int nTaskShow);

[DllImport("coredll.dll")]
public static extern int MoveWindow(IntPtr hwnd, int X, int Y, int nWidth,
int nHeight, bool bRepaint);

Enjoy!

Friday, September 23, 2005

BB : pushScreen always displays the menu on top

Really annoying problem. You invoke pushScreen and lo and behold the current menu pops up on top of the new screen. You have to escape out.

Lots of traffic on the Net about this. Half of the people say that it is not the default behavior and refer you to the Blackberry samples that don't exhibit this behavior. The other half say "Stuff the samples, I can SEE the problem and it's driving me nuts".

And the reason is the humble button (ButtonField). You aren't supposed to use buttons, rather add the action to the menu. But some users are Windows centric and WANT a button. The samples don't use a button; hence don't exhibit the behavior.

The problem is that the click is passed onto the next screen and so invokes the menu. The trick is to dump the click. You do this by:

bf = new ButtonField ("Submit", Field.FOCUSABLE | ButtonField.CONSUME_CLICK);

Problem solved.

Enjoy!

OpenNETCF : Getting OpenNETCF code from the Vault

The latest code is always available from the Vault (a VSS lookalike).

(NOTE: The code under the "Source" tab at www.opennetcf.org is NOT the latest).

For multiple files, install the Vault client application from here:

http://www.sourcegear.com/vault/downloads.html

or

For single files, direct from source control here:

http://vault.netcf.tv/VaultService/VaultWeb/login.aspx

login = guest
password = guest

Enjoy!

.NET : Serial classes

There is no support in either CF or the full framework.

OpenNETCF has serial classes which can run on both platforms.

There are some samples here:

http://www.opennetcf.org/PermaLink.aspx?guid=0e593c58-7305-46d1-b8f8-9559152d5e1e

with a write-up called "P/Invoking Serial APIs in the Compact Framework" by Chris Tacke here:

http://www.opennetcf.org/PermaLink.aspx?guid=01116b3d-9770-4f83-9fee-253c0410d7a4

For the full framework, John Hind has an excellent article called "Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications" here:

http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx

Enjoy!

CF : Enabling network connection from a PPC emulator

Assuming the desktop that runs the emulator has a network connection ...

This is using PPC 2003 emulator / PPC 2002 is similar.

Start / Settings / Connections

Click Connections icon.

Advanced / Select Networks

Change dropdown for Internet connection to "My Work Network"

Edit / Proxy Settings

Check the checkbox "This network connects to the Internet"

OK all the way out.

Try IE - should now have a network connection from the emulator.

Enjoy!

(Compact Framework)

SOAP : "Dynamic" web service

Using SOAP and web services, this is something I have found useful.

Basically, the original question was: "Is it possible to allow an application to access webservices without specifically adding a web reference in the project? In other words, can an application be created which allows the 'user' to specify the URL, and then call whatever webmethods may exist on that server?"

This may be a bit of a hack but hey "If the shoe fits ....".

What you could do is have dummy stubs

e.g. int Method1 (int)
string Method2 (string)

and so on and code each differently on the server side.

So Method1 on URL1 will do something completely different to Method1 on URL2.

The important thing is that the WSDL signatures are correct.

Enjoy!

SQL CE : TIP: Typing complicated queries using Query Analyzer

Ever tried to do this on a mobile device like a PPC? Using the small SIP is guaranteed to give one eye strain.

I use the "ActiveSync Remote Display" from Windows Mobile Developer Power Toys.

This allows a remote display of the PPC on your desktop and you can use your keyboard to type the query in.

Enjoy!

Misc : Wikitravel

Wherever you are in the world while reading this, why not visit Wikitravel and enter some details about where you live, things to do etc.

It's a Wiki site along the lines of Wikipedia.

As they say in Wiki speak : Plunge forward.

Thursday, September 22, 2005

BB : Installing an application from Desktop Manager

The first thing to remember is that you need to generate an alx file. Either right-click on the project in the "Files" window or under "Project" in the toolbar.

Then start Desktop Manager. (I have found that sometimes it helps to use the version of Desktop Manager on the CD that comes in the box with your Blackberry.)

Then "Application Loader". Then "Add" and browse to the alx file and select it. Then confirm that the checkbox is ticked and "Next".

It helps if you have a "Title" and a "Version" in your project properties under "General" . Also an "Output File Name" under "Build". That way Desktop Manager can tell you which file is which rather than a list of blank lines!

Enjoy!

Misc : WTP installed finally on Eclipse

Been battling for a while getting Eclipse WST (Web Standard Tools) and WTP (Web Tools Platform) to run on Eclipse 3.0. Eventually gave up on it and installed 3.1. It's a monster download and you need to add the optional WTP plugin.

The software updates feature under Help makes it a snap. Remember to click the “Select Required” button to enable the features required by WTP which are not already installed. Got it all installed and now can right-click on a WSDL file and select “Validate WSDL”.

Enjoy!

Misc : Number of IDE's for development

So many IDE’s on my desktop just has to lead to confusion.

Eclipse 3.1 for basic Java
Weblogic Workshop for Internet stuff
Blackberry 4.0.2 for Blackberry development
Visual Studio 2003 for .NET, C++, CF, PPC and Smartphone.
eVC++ 3.0 and eVC++ 4.0 for older mobiles
Java Studio Mobility for J2ME

And yes, most of them are used most of the time! Gets really confusing when you have more than one open at the same time especially if they require different languages.

That’s 11 platforms – can anyone beat that?

Notice the only real gap is Visual Basic – I’m not a big fan.

Enjoy!

Wednesday, September 21, 2005

BB : Running simulator standalone

The Blackberry IDE puts the project files into e.g. :

C:\Program Files\Research In Motion\BlackBerry JDE 4.0.2\simulator

There will be .cod, .cso, .debug and .jar files for each project.

To run the simulator standalone, ensure that the project’s files are in the above directory, cd to the directory and then run the “type”.bat file in a command prompt.

e.g. to run the 7100v simulator, run 7100v.bat

Enjoy!

Friday, September 16, 2005

Misc : Other automatic Pings

Two other sites I've used for automatic Blog pinging are:

King Ping : http://www.kping.com/

and

Pingoat : http://www.pingoat.com/

Enjoy !

Thursday, September 15, 2005

Misc : Ping-O-Matic

Can't recommend this Blog pinger highly enough.

Why do the pings individually when you can aggregate them all in one?

http://pingomatic.com/

Does Weblogs, Feedster, Technorati and more.

Nice one!

Enjoy!

Misc : Google Blog Search

So cool!

http://blogsearch.google.com/

In one fell swoop, I can find nearly all my Blog entries via Google. The old Google search found around 10% of them.

Read about it here:

http://www.google.com/help/about_blogsearch.html

In particular:

  • How do I find Blog Search?
  • Can I subscribe to search results?
  • What search operators are supported?

Enjoy!

Wednesday, September 14, 2005

SQL : Date format and style

I'm always getting confused between the UK and US formats:

For UK format i.e. dd/mm/yyyy, the style parameter is 103

CONVERT (DATETIME, '18/12/2005 00:00:00', 103)

For US format i.e. mm/dd/yyyy, the style parameter is 101

CONVERT (DATETIME, '18/12/2005 00:00:00', 101)

And I really wish that people would give examples like '18/12/2005' where it's quite obvious which is the date and which is the month instead of the normal examples like '04/06/2005' where it could be either.

Enjoy!

Friday, September 09, 2005

BB : Showing the Blackberry screen on a PC

You can do this in Windows Mobile with one of the Power Tools.

It's really useful for demos. Just hook up the native device via Active Synch. , display the device screen on your PC, drive it from your PC mouse and keyboard and you can enlarge it and project it, make screen shots etc.

Beats the hell out of 10 people elbowing each other out of the way to look at the miniscule screen.

But there is no such facility on Blackberry. That sucks major league big time.

You have to do the demo. using the simulator. That leads to "smoke and mirrors" comments. And the Blackberry simulator DOESN'T simulate. It will run perfectly on the simulator and throw exceptions on the device.

My previous post concerning "blocking operation not permitted on event dispatch thread" is just one such example.

Enjoy!

BB : The dreaded "blocking operation not permitted on event dispatch thread"

Seen this message on your Blackberry?

“Uncaught Exception:blocking operation not permitted on event dispatch thread”

Have you done this?

A new class for threading:

class NewThread extends Thread

and in this you have a

public void run ()

Then in the main thread, you have

NewThread nt = new NewThread ();
nt.start ();

In NewThread, to access the UI you need:

UiApplication.getUiApplication().invokeLater
(new Runnable()
{public void run()
{
Dialog.alert ("Some message");
}
}
);

To access fields in the UI, use get / set methods (which are declared in the main thread) from the Runnable code above. I used to have the blocking exception until I changed to the above.

Enjoy!

Thursday, September 08, 2005

BB : BlackBerry MDS Studio

This is part of the BlackBerry Mobile Data System v4.1

http://www.blackberry.com/developers/promos/mds.shtml?CPID=OTC-devsept02

From the FAQ:

"BlackBerry MDS Studio is a powerful visual application design and assembly tool that allows developers to quickly create applications using drag and drop functionality."

It's different to a vanilla J2ME application because "BlackBerry MDS Applications are applications developed using BlackBerry MDS Studio and that require BlackBerry MDS Runtime Environment to be installed on the device in order to run."

So much like Windows Mobile where you also have to load the Compact Framework.

One question?

"Q: Does BlackBerry MDS support Microsoft .NET?
Yes. BlackBerry MDS Applications can integrate directly with Web Services created with
Microsoft .NET tools and running within a Microsoft .NET environment."

That's actually saying you can create a Blackberry client that speaks via web services to a .NET server. It doesn't mean that you can run .NET applications on a Blackberry. Isn't that the usual meaning of "support"?

Best of all though "BlackBerry MDS Studio is based on Eclipse. Eclipse is a widely used open source IDE framework that can be extended to create software development tools for particular types of applications."

Got to be heaps better than the current IDE. Finally some standardisation and another feather in the cap for Open Source.

Bring it on!

Enjoy!

Wednesday, September 07, 2005

Misc : Blackberry vs Compact Framework development

You can say what you like about Microsoft but the Compact Framework development environment and support creams RIM and Blackberry hands down, TKO, no contest!

  1. Visual Studio is a much better, less buggy IDE than the Blackberry JDE.
  2. Deployment is much easier with Active Synch as opposed to Desktop Manager. It's basically another folder and you can drag and drop all kinds of files anywhere.
  3. Blackberry Forum support is a joke. Does anyone from RIM actually read it? Most of the posts go unanswered for days on end. Compare this to the Google group "microsoft.public.dotnet.framework.compactframework". You get answers within hours and the quality is excellent with such people as Peter Foot, Paul G Tobey, Daniel The Moth, the two Alex's and so on.
  4. CF has the superb OpenNETCF. RIM has nothing even remotely comparable.
  5. Do a Google search for some CF samples. You are spoiled for choice. Do the same for Blackberry - the quickest way I know to return zero Google results. If anyone out there is doing Blackberry development, they certainly don't seem to be posting it to anywhere.
  6. To be fair, Blackberry is constrained by the J2ME environment in terms of the quantity and richness of the components but it's still no contest.

Enjoy!