# Friday, March 19, 2004

Free space on Storage Cards

You can determine the total size of a Storage Card and available free bytes using the GetDiskFreeSpaceEx API function. Below is a "mini-wrapper" around the function which returns a structure with the three return values. You'll notice in this example I'm marshalling longs (64bit Integers), values greater than 32bit cannot be marshalled by value but can be marshalled by reference as in this case. The DiskFreeSpace struct contains three long members to hold the accessible free bytes, total bytes and total free bytes.

public static DiskFreeSpace GetDiskFreeSpace(string directoryName)
{
    DiskFreeSpace result = new DiskFreeSpace();

    if(!GetDiskFreeSpaceEx(directoryName, ref result.FreeBytesAvailable,
        ref result.TotalBytes, ref result.TotalFreeBytes))
    {
        throw new Win32Exception(Marshal.GetLastWin32Error(), "Error retrieving free disk space");
    }
    return result;
}

public struct DiskFreeSpace
{
    public long FreeBytesAvailable;
    
    public long TotalBytes;
    
    public long TotalFreeBytes;
}

[DllImport("coredll")]
private static extern bool GetDiskFreeSpaceEx(string directoryName,
    ref long freeBytesAvailable,
    ref long totalBytes,
    ref long totalFreeBytes);

 

Or if you prefer Visual Basic:-

Public Function GetDiskFreeSpace(ByRef directoryName As String) As DiskFreeSpace

    Dim result As New DiskFreeSpace

    If GetDiskFreeSpaceEx(directoryName, result.FreeBytesAvailable, result.TotalBytes, result.TotalFreeBytes) = False Then

        Throw New System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), "Error retrieving free disk space")

    End If

    Return result

End Function

Public Structure DiskFreeSpace

    Public FreeBytesAvailable As Long

    Public TotalBytes As Long

    Public TotalFreeBytes As Long

End Structure

Private Declare Function GetDiskFreeSpaceEx Lib "coredll.dll" (ByVal directoryName As String, ByRef freeBytesAvailable As Long, ByRef totalBytes As Long, ByRef totalFreeBytes As Long)

#    |
# Thursday, March 18, 2004

A day of upgrades

I followed Neil and Alex's lead and upgraded my blog to dasBlog too. Luckily because dasBlog is an evolution of BlogX the migration was pretty smooth. I may well tweak the theme slightly yet though because I miss my roadsign :-)

I've also flashed my iPaq 2210 with the latest 1.10 ROM (Thanks to Ed at Pocket PC Thoughts for the heads up). This includes a number of previous patches, sadly it has .NETCF SP1, not SP2 so that will still require a RAM install. However doing a ROM flash is always a good time to clean out the crud so my iPaq is nice and tidy (for the moment at least)

#    |
# Thursday, February 19, 2004

So what do you think of OpenNETCF?

The OpenNETCF Survey

As we are approaching our first anniversary (and so is the .NET Compact Framework itself which was officially announced last March) we are interested to understand what you think of the code, articles etc we have created so far and what you would like to see from us in the future. We would really appreciate it if you could spare a few minutes to fill in our short survey, you can fill it anonymously if you like or if you provide details you'll be entered into a draw for some secret OpenNETCF goodies - we'll announce the winner during the upcoming MDC 2004 week.

 

#    |

Microsoft Mobile Dev Con just over a month away

Kevin Lisota has just posted about his excitement for the upcoming MDC in San Francisco. It's shaping up to be a really interesting event and of course OpenNETCF will be providing an exciting session:-

"CLI345 - Developing Real-world Smart Device Applications with Visual Studio .NET 2003, .NET Compact Framework and OpenNETCF SmartDevice Framework
The .NET Compact Framework is a powerful tool for a mobile developer. To fully utilize its potential in a real-world application, a developer needs access to the native API and intrinsic Windows CE controls. OpenNETCF SmartDevice framework is designed to address these needs."
 
There will also be a number of worldwide events to follow offering MDC content nearer to you.


#    |
# Saturday, January 31, 2004

.NET Compact Framework Poster

To celebrate the upcoming release of a full featured developer poster detailing the .NET Compact Framework class hierarchy, Jon Wells is holding a giveaway for a "Poster and Coaster". This consists of the poster and a CD-Rom full of goodies from the MSDN mobility website. There is an image of the poster available here on Jon's blog.

#    |

Multiple icons in .NETCF projects

A discussion came up on the newsgroup regarding using a system tray icon from within .NETCF code and how the icons are handled. The way this is done (including in OpenNETCF's NotifyIcon control) is to use the icon of the calling assembly using the native LoadIcon function.

The tray icon needs to be a 16x16 icon, however to look right in the Programs screen the application needs a 32x32 icon too. There is some confusion of how to handle multiple icons within a .NETCF application. Adding multiple icons through embedded resources does not make these icons accessible from native functions such as LoadIcon because .NETCF does not store these icons as Portable Executable (PE) resources, instead using the .NET method with manifests. Therefore in the normal build process the only PE icon to be built into the executable will be that which is specified in the ApplicationIcon property in the project properties:-

The icon file in this case was created using Visual Studios icon editor, this contains two icons: 32x32 256 color and 16x16 256 color. You can download the sample .ico here. To illustrate which is used they contain merely a number with their size (32 and 16 respectively).

In the Start Menu / Programs the 32 icon is used to display a correctly sized icon. When the NotifyIcon is created it automatically uses the 16x16 sized image.

 

One final note about the application icon is that .NETCF executables all store their application icon with the resource identifier 32512. so a native handle to the icon of the currently executing application can be got using

        IntPtr hIcon = LoadIcon(GetModuleHandle(null), "#32512");
    

LoadIcon is within Coredll.dll and you'll find the P/Invoke details in the OpenNETCF Smart Device Framework source. When you have finished with the handle you should call DestroyIcon to free up resources used.

Sample Icon

#    |

.NETCF Performance

Alex recently posted a link in his blog to a presentation discussing the architecture of the .NET Compact Framework which has some interesting details on which parts are ported from the full framework and which are ground-up re-writes specifically for the Compact Framework. One of the other interesting items is the performance statistics which show the difference between the Tech Preview (doesn't that seem like a long time ago now) and "Today" (which represents when this presentation was given in 2001).  It would be very interesting to see how the release and the subsequent two service packs have made further progress on these figures.

 

#    |

The future according to Vodafone

Vodafone have a promo site indicating their vision of the future with mobile devices. While you might find the over-done flash a little irritating it does have some interesting tid-bits including an organic foldable map with location based information...

http://www.vodafone.com/flash/futures/

#    |