Intermec Scan to Exit

We had another very curious incident, this time on an Intermec terminal. Each time the terminal scanned a barcode our application would immediately exit.  No warning, no exception, nothing but an immediate exit.  And it wasn’t even a complicated application, just a simple prototype.

What made this even more curious was that it didn’t happen on all of our Intermec terminals and hadn’t occurred in the past with our other customers.  A few more details will make the problem a little clearer.  First of all we are developing in .NET CF 2 with VS.NET 2005 and our SNAP application framework.  The Intermec 760B terminal is running Pocket PC 2003 (OS 4.51 Premium with PSM 3.93.1 for 32MB Flash) and the Intermec 2.4 IDL.Intermec 700 Series Terminals

So it was a matter of rolling up our sleeves and getting down in to the bowels of the source code.  Initially we suspected that there was an exception in the scanner dll causing the application to abort.  We tried the usual tasks such as walking through the code (difficult since scanning is event driven), and catching exceptions on invocation instead of where they are caught, all to no avail.  Finally, it was a matter of controlling the scanning to catch the error, where we found a Windows Message conflict, essentially programmatically triggering the scanner to control the execution in the debugger.

Apparently Intermec has implemented their scanner code using messages and happened to assign the same Window Message ID (WM_USER+1 =  0x401) that we were using for exiting a sequence of forms (in this case out of the application).  And that’s the end of the application.

So what does that mean.  The first thing one could argue is that a system object like this should not expose the window messages to the application, or at least not use one that is quite so common. And I’d think you’d have a pretty good argument there. 

So the simple solution is that rather than using WM_USER as our Message ID base, we could use a value that is unique within the system.  The easy way to do this is to register the window message with the OS and request a unique id.  Simply use the method:

[DllImport("CoreDll.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern uint RegisterWindowMessage(string lpString);

static uint WM_MY_MSG = // use RegisterWindowMessage to ensure unique
  RegisterWindowMessage("WM_MY_MSG");

Of course this isn’t 100% perfect since you can still have people using the same string to register their message.  To take it the next step you can create a GUID, but I think that’s getting a bit much.  Just use a reasonable unique name and everything should be fine. 

References:

0 thoughts on “Intermec Scan to Exit

  1. Pingback: Intermec Scan to Exit « Mobile Musings

Leave a Reply

Your email address will not be published. Required fields are marked *