miercuri, 7 septembrie 2011

Activate and Configure RNDIS for Windows CE Based Devices

To activate RNDIS and communicate over TCP/IP with the Windows CE based device from Windows 7, I had to follow these steps:
1.      Modify the key [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\DefaultClientDriver] to RNDIS.

2.      Save the registry modifications and restart the module.

3.      In Windows, ActiveSync will no longer work and a generic RNDIS device will be listed in Device Manager,under Unknown Devices.

4.      Right click the generic device and select to install a driver.

5.      In the next window, select “Browse my computer for driver software”:
                                              

6.      In the next window, select “Let me pick from a list of device drivers on my computer”:

7.      In the next window, select Network Adapters from the Common Hardware Types list and click Next.

8.      In the Select Network Adapter window, select Microsoft Corporation and from the list on the right, Remote NDIS Compliant Device. Click Next.


9.      You will get a warning message; you need to ignore it and install the new driver. After installation the RNDIS device will be listed under Network Adapters in Device Manager.

10.      On the PC side, in Network Connections, right click on the new adapter and assign it a new IP address, typically: 192.168.55.101 with mask 255.255.255.0. Leave the other fields blank.

11.      In Windows CE, open Settings->Network and Dial-Up Connections and double click on the RNDIS adapter. Assign a new IP address, typically 192.168.55.100 with mask 255.255.255.0. Leave the other fields blank.

12.      Now test communication between the PC and the Windows CE device by pinging the device’s address.

            Important Note: In this setup, Active Sync will no longer work. It can only be restored by modyfing the [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\DefaultClientDriver] back to its original value (Serial_Class).

marți, 6 septembrie 2011

Exception messages in .NET Compact Framework

The .NET Compact Framework team decided not to include libraries that contain error message strings by default since these would occupy more space and are in most cases not meant for the end users.
As developers, we need to these messages for debugging purposes, specially when we are not using Visual Studio. Whenever an exception occurs, the log entry for it would look like this: "An error message cannot be displayed because an optional resource assembly containing it cannot be found". This post of the .NET Compact Framework team explains what we need to do in order to enable descriptive exception messages on our Windows Mobile/ CE based device.
Basically what you need to do is copy the System_SR_[Language].CAB  file from your computer to the device and then double click it to install the .cab. If your language of choice is English, you need to copy the System_SR_ENU.cab, installed by default in C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\Diagnostics.
After installing this .cab file on the mobile device, you will start seeing descriptive exception messages, that are far more helpful.

Learn more on overall Compact Framework development in C# from Programming .NET Compact Framework 3.5 (2nd Edition) by Paul Yao and David Durant.

sâmbătă, 13 august 2011

joi, 4 august 2011

Ignore Enter Key Press for .NET Button

According to the documentation found on MSDN, "A Button can be clicked by using the mouse, ENTER key, or SPACEBAR if the button has focus."
It took a while until I have found how to disable the Enter and Spacebar keys to produce the Click event for a form button that has focus. The solution is to override the ProcessCmdKey method in a derived class and catch the Enter key press in that method and return before it gets to be processed by the method in the Button base class. Here is the basic class I used to accomplish this.

/// <summary>
/// A class that inherits the System.Windows.Forms.Button class and ignores
/// the ENTER key press that also triggers the click event.
/// </summary>
internal class ButtonNoEnter : System.Windows.Forms.Button
{
    protected override bool ProcessCmdKey( ref Message msg, Keys keyData )
   {
       if( keyData == Keys.Enter || keyData == Keys.Space )
      {
            return true;
      }
      return base.ProcessCmdKey( ref msg, keyData );
    }
}