Wednesday, March 28, 2012

nHibernateCF TP3 with new functionality

nHibernateCF TP3 will be released during the next two weeks.

In the TP3 version of nHibernateCF, I’ll a couple of new function which I still missed during the development of the new demo project will is released in TP2 of nHibernateCF.

The new functionality will be in the Criteria part of nHibernateCF.

- Aggregate functions like Min, Max and Avg.

Min(fieldName) and Max(fieldName) will return the complete object for the condition.

Avg(fieldName) will return the average value for the condition.


- a seperate Count function.

Count() will return the number of object which will be returned in the List<T>()/List()/Pages functions.

- a Pages function to receive a part(page) of the resultset.

Pages[] will return a Page (=> a IList<T>) of the result set. The size of a page is defined with the MaxPageSize property.

As a general improvement, I ‘ll add a float data type for currency values.

Friday, March 23, 2012

New version of nHibernateCF with new demo project released

During the development of nHibernateCF, I took notice that is nice and important to have a more complex demo project which shows the capabilities of nHibernateCF.

I decided to create a project named ‘DeliverySystem’. It contains a couple of data objects and forms which demonstrates how can nHibernateCF can used on Windows CE/Windows Mobile powered devices.

During the development of the demo project, I saw some bugs in nHibernateCF which I fixed.

Fixed bugs:

  • Bags will be updated updated correctly without doubling the elements which a still in the bag.
  • Criterias can be used for bags

Furthermore, I tried to gave all methods, enumerations, etc. an Intellisense documentation so that is easier for developers to use nHibernateCF in their projects.

I also added a new project to the nHibernateCF solution called ‘Tools’. At the moment it contains just user controls. One control displays all logging information which nHibernateCF generated, the other displays all exceptions which nHibernateCF may have.


Projects ‘DeliverySystem’ and ‘DeliverySystemData’

I decided to split the demo project in two separate projects. The ‘DeliverySystem’-project is the main project which contains all the forms and nHibernateCF-stuff.


Project ‘DeliverySystem’

The ‘DeliverySystem’-demo-application is just a kind of simple application for mobile salesman/woman. It is not a stylish application, just a tech demo which demonstrates the capabilities of nHibernateCF. I will show here for the moment all screen which the application contains. It is a kind of short manual how the application should be used. You’ll find all the method calls in the source code of the demo-application and in one of the following blog entries, I’ll talk about them.



At the first time, when the application started, the database will be created and you have create a new user.



For the usage of the application, a couple data is required. If not all required data is available, this screen will be displayed. If a type of data is available, the button in this screen will be disabled. In the Program menu is another possibility to add or edit these data.



At the first button, you can add and/or edit some information for the both(or more) genders.
The first form shows a list with all available genders.
With the right menu you can add a new gender.

The look-and-feel of the kind, how the application manipulates the genders (only in the demo-application) is more often used in the demo-application like when you manipulate salutation, article groups or articles.



The add/edit form is just a simple dialog box with some controls to display or enter some data.




In the next step you have to add a couple of salutations, like one or two for each gender.


In this screen you need to select a gender for the current salutation, you can add a text for the salutation in a letter, a short and a long description.



There you can select the gender for the salutation.



After you have done that, you have one or more salutations.




The next step is to add a couple of groups for different types of articles you might have.


015 016

The last of the first four important steps in to add some articles. In the demo-application you can give them a name and two description, a short and a long one. At least you can select one or more groups of articles to which the current article should count.


Up to now you can use the demo-application. The next steps are to add the customers and orders.


This is the new(or normal) login screen after the first start of the demo-application.


This is the new(or normal) start screen after the login.
To edit or add the basic data you’ll find the possibilities in the ‘Program’ menu.



  The customer in the demo-application contains just a few properties. A salutation (with gender), first- and lastname, one or more addresses. In most cases in the demo-application, all list controls have a context menu which allows you different operations.


An address in the demo-application has just a few properties, too. You can enter in the screen a street name, a house number, an additional house number, a postal code and the name of town where the customer lifes.

After clicking on the ‘Customers’ button on the start screen, you’ll get a well-known list. In this case it is the list of all available customers. After the first start the list should be empty. With clicking on the ‘New’ button in the lower left corner of the screen, you can add a new customer.



In this list, all available customers will be displayed. Select the customer of your choice and click on ‘Select’

With this screen, you’ll able to enter all data for the new order. Edit the date of the order, select addresses for delivery and invoice and add some articles from your list of articles.

If you have added one or more customers, it will be the time to add an order to a customer. With clicking on the ‘Orders’ button at the start screen, you’ll get another well known list screen. At this point, it is a list with all available customers to which you can add a new order. Select a customer an click on the ‘Select’ button in the lower left corner of the screen.



The addresses in this list are all from the list of addresses of the selected customer.

To add one or more articles to the order, just use the context menu to do that. There will be open a new screen in which you can search for the article/s of your choice.



After you filled all controls, the order screen should look like this one. Press in the ‘Save’ button on the lower left corner of the screen to save the order.


There is another screen in the demo application which you can reach from the ‘Program’ menu on the start screen. This screen contains all the status information from nHibernateCF.


On the left tab there all logging information which nHibernateCF generates during the run time and on the right tab there all exceptions listed which nHibernateCF might have.

Project ‘DeliverySystemData’

The ‘DeliverySystemData’-demo –application contains the data objects and some additional helper methods which die ‘DeliverySystem’-demo-application needs. As an example, I’ll only name a method to make a specified address as default address for a customer in a list of addresses.

Thursday, February 2, 2012

nHibernateCF for .Net Compact Framework

Today, I would like to annouce ‘nHibernateCF’ for the .Net Compact Framework and the SQL CE-database. At 5th february 2012, a first technical preview version will be released on Codeplex.

nHibernateCF is an object-mapping framework for WindowsCE- or Windows Mobile-powered devices.

Like Hibernate or nHibernate, nHibernateCF will provide a set of functions for database-applications on mobile devices.

In this first technical preview, not all planned functions are implemented. Currently available are this functions:

  • creating a database with a set of .hbm.xml-files
  • running simple insert-, update- and get-operations on the database by using simple plain .Net objects
  • creating and running a more complex criteria query

During the next month, I am planning to add more functions and tools to the nHibernateCF-framework.

Thursday, August 4, 2011

I am back…

…from a 18 month-trip developing enterprise solutions on the full .Net Framework.

…Back with a couple of new, hopefully good, ideas in my mind which I want to realize.

Ideas, mostly for background and/or backend-services and some, but not so much, for the user-interface.

The most powerful and inovative idea is a component for databases on the .Net Compact Framework.

Monday, October 5, 2009

.Net CF is calling…

This article describes a kind of interprocess communication between a .Net-application and a native c++-application on WindowsCe/WindowsMobile-based devices.

The reason for this project was my current task, a set of native DLLs for an external hardware which should connected to the mobile device. The data structure from the DLLs is very complex and very hard to implement in a .NetCF-application, so I decided to build a native c++-application for the communication between the DLLs and .NetCF-application.

The communication between the DLLs and the c++-application was very easy, cause I got a good manual, how I could use the DLLs. It was much harder to find a way to communicate from the C++-application with the .NetCF-application.

The way, which I found, was to communicate via Windows Messages. If you want to transfer data between application with Windows Messages, you have to use the SendMessage()-function together with the WM_COPYDATA-message. Additionally, you have to use the COPYDATASTRUCT-struct from the Windows API.

In this article, I will explain it with a simple data struct, called ‘ownData’. Here is the definition of ‘ownData’ in C++.

struct ownData
int ID;
byte data[500];

The basic structure of the communication between both applications looks like that. Both apps have a receiver- and a sender function which handles all necessary steps.

basic structure for the communication


On the C++ – side its quite simple. Everything you need is nearly build-in. You just have to include some header files and everything is OK.

For a short example, it is enough to include the “windows.h”-header file.

So, I create in Visual Studio a new C++-project for embedded devices as plain Win32-C++-project. The main.cpp-file looks like that…

#include <windows.h>

int WINAPI WinMain(HINSTANCE h, HINSTANCE, LPTSTR arg, int nCmdShow)

// define a new handle for the wndclass
HWND hMain = 0;

// create and define a new wndclass

// this function handles all Windows Messages
wc.lpfnWndProc = MainWndProc;

wc.hInstance = h;
wc.hbrBackground = (HBRUSH)(COLORWINDOW+1);
wc.lpszClassName = L”SENDER”;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;

// register new wndclass wc

// create a new window from wc

// hide hMain
ShowWindow(hMain, SW_HIDE);

// creating a Message var
MSG msg;

// joining the message pump
while (GetMessage(&msg, NULL, 0, 0))

// setting the return value for WinMain
return msg.wParam;


In the MainWndProc-function, I will filter all Windows-Messages. My special interest is on the WM_COPYDATA-messages. They contains the sent data from the other application. Here is my function…


// checking msg
switch (msg)
// parse the lParam-parameter in a PCOPYDATASTRUCT

// parse pcds->lpData in your own data structure
ownData* od = (ownData)(LPSTR)pcds->lpData;

// do whatever you want
// with your ownData od

// exiting

//at last, your should run the DefWindowProc and setting the return value
return DefWindowProc(hwnd, msg, wParam, lParam);

So, now we have all functionality to get answers from another application. Now we need the functionality to send data to another application. I have create an own function for that. In this function, I used the FindWindow()-function from the Windows API. They normally need two parameters, a classname and a windowname. In this case, I want to find/contact a .NetCF-application.

Normal’ .NetCF-applications have ‘#NETCF_AGL_BASE_’ as classname and the windowtext as windowname.

a normal .NetCF-application in the RemoteSpy

In the case, I used a new class which inherits the WindowMessage-class from the ‘Microsoft.WindowsCE.Forms”-namespace. More to that aspect will follow later in this article. When I use the WindowMessage-class, you got a new entry in the the handle-list from WindowsCe or WindowsMobile. The new handle has a classname equal “#NETCF_AGL_MSG_” but no windowname. You can set the windowname  manually by the classes property.

a .NetCF-application without a window but with an instance of the WindowMessage-class

At next, I implemented a send function in my C++ application, which has a ownData-parameter. The function creates a new COPYDATASTRUCT which my own data, looks for the receiver window and sends the COPYDATASTRUCT to the window if its exists.

static void Send(ownData data)

// create a new COPYDATASTRUCT

// putting the data from ‘data’ in ‘cds’
cds.dwData = (WPARAM)0;
cds.cbData = sizeof(ownData);
cds.lpData = &data;

// creating a new HWND from a running application
HWND hReceiver = ::FindWindow(_T(“#NETCF_AGL_MSG_”), NULL);

// checking hReceiver
if (hReceiver != NULL)
// sending the cds
SendMessage(hReceiver, WM_COPYDATA, (WPARAM)0, (LPARAM)&cds);

.Net Compact Framework (C#)

On the receiver side, I had a managed .Net Compact Framework application which is written in C#.

At first, we need some things from the Windows API. We don’t have here in C# a build-in struct like COPADATASTRUCT, so we need to create it. It is nearly the same as in C++.

public struct COPYDATASTRUCT
public System.Int32 dwData;
public System.Int32 cbData;
public System.IntPtr lpData;

At next we need the FindWindow()-function from the Windows API. Here is the declaration that we can use it in C#.

static extern System.IntPtr FindWindow(System.String lpClassName, System.String lpWindowName);

Both things, COPYDATASTRUCT and FindWindow() are necessary in the application.

Here is the declaration of the ownData struct in C#. Here, it is very important that the byte-array will be declared manually with a defined size of 500 entries like in C++. If this will not be done, you will have a lot of trouble during runtime.

public struct ownData
public System.Int32 ID;
[System.Runtime.InteropServices. MarshalAs(System.Runtime.InteropServices. UnmanagedType.ByvalArray, SizeConst = 500)]
public byte[] data;

As I said above in this article, I created a new class which inherits the WindowMessage-class from the Microsoft.WindowsCE.Forms-namespace. In this new class, I’ve the WndProc-function overwritten. With my own function, I’m able to check and handle all incoming Windows Messages.

protected override void WndProc(ref Microsoft.WindowsCE.Forms.Message m)
// check m.Msg
case 0x4A: // 0x4A = WM_COPYDATA
// extract the own data from the Windows Message m
ownData data = this.ExtractDataFromMessage(m);

// do whatever you want with your data

// run base.WndProc
base.WndProc(ref m);

In the overwriten WndProc function I call a function named ExtractDataFromMessage(). This function extract the sended data from the Windows Message into my own data struct. These function works with pointers, so I had to declare her as unsafe. I also had to enable the unsafe flag in the project properties.

unsafe private ownData ExtractDataFromMessage(Microsoft.WindowsCE.Forms.Message msg)
// delcare all vars with are needed
ownData data = new ownData();
IntPtr* targetPointer;

// create cds and extract the COPYDATASTRUCT data from the Windows Message
cds = (COPYDATASTRUCT)System.Runtime.InteropServices. Marshal.PtrToStructure(msg.LParam, typeof(COPYDATASTRUCT));

// get the targetPointer
targetPointer = &cds.lpData;

// get the data from the COPYDATASTRUCT
data = (ownData)System.Runtime.InteropServices. Marshal.PtrToStructure(cds.lpDAta, typeof(ownData));

// return the data
return data;

In the C#-application, I also have a Send-function, which encapsulate some functions. The send-functions has a ownData-parameter. In this function, I retrieve the addresspointer of ‘data’, create a new instance of COPYDATASTRUCT in my C#-application, retrieve the addresspointer of it and create a new Windows Message and send with Microsoft.WindowsCE. Forms.MessageWindow.SendMessage().

private void Send(ownData data)
Message msg = new Microsoft.WindowsCE.Message();

// create a new pointer for ‘data’
System.IntPtr pData = System.Runtime.InteropServices. Marshal.AllocHGlobal(System.Runtime.InteropServices. Marshal.SizeOf(data));
Marshal.StructureToPtr (data, pData, false);

// setting cds
cds.dwData = 0;
cds.cbData = System.Runtime.InteropServices.
Marshal. SizeOf(data);
cds.lpDAta = pData;

// create a pointer for ‘cds’
System.IntPtr pCds = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf(cds));
Marshal.StrucutreToPtr (cds, pCds, false);

// getting the server-application
System.IntPtr server = FindWindow(“SENDER”, “Sender”);

// checking server
if(server != null)
// setting ‘msg’
msg.HWnd = server;
msg.Msg = 0x4a;
// 0x4a = WM_COPYDATA
msg.WParam = (System.IntPtr)0;
msg.LParam = pCds;

// sending msg
Microsoft.WindowsCE.Forms.MessageWindow.SendMessage (ref msg);

// clearing the allocated memory

SendMessage(), PostMessage(), SendNotifyMessage(), etc…

The Windows API contains a lot of functions to send Windows Message from on application to another. MSDN says that you have to use the SendMessage()-function. Correct! Why? For sure, you can use PostMessage() or SendNotifyMessage() as well, your receiver-application gets the Windows Message, but the encapsulated data pointers are corrupted and all your data is lost.


Transferring data with Windows Messages is a nice method to transfer data fast from an application to an other application. You can compute the data immediately in the receiver application. It also could be a way for a .Net developer to use external hardware on mobile devices, when the drivers are very difficult to use in .Net.

Friday, June 12, 2009

Extending the desktop with your PlayStationPortable

A couple of days ago, I found a little nice potion of software. It’s called pspdisp. This software extends the windows desktop on your Sony PlayStationPortable.

The software contains of two parts. You have to install one part on the PlayStationPortable, the second part, you have to install on your Windows PC.

Pspdisp allows you to connect the PlayStationPortable with your Windows PC via USB or via WLAN. I only tried it via USB. In the display properties dialog, you can setup your new screen.


On my analog desktop,I still got two displays, but with my PlayStationPortable, I got a thrid one.


Ok, the resolution is not very large, but for small applications it is enough.


On your PlayStationPortable, you need a costum firmware.

Friday, February 27, 2009

Extended classes on more than one platform

Inspired by this article from Kai, I was tried to extend classes for the .Net Compact Framework with methods for the .Net Framework.

I had to work with graphics on the .Net Compact Framework. The opportunities in .Net Compact Framework are a little bit rare. So I decided to handle a part of the functionality on the desktop.


During my work, I created a class, which originally based on an older idea of myself. On the .Net Compact Framework it is not possible to open images as 32BitARGB image. The color-values for RGB are Ok, but the Alpha-information will be ignored by the .Net Compact Framework.

Now, I created an application for the Desktop, which uses the .Net Compact Framework-class. I wanted that, because I don’t want to have redundant source code for both applications. So I tried to extend the existing class with some methods for the Desktop .Net Framework. The new extended methods contains source code for the Desktop including all opportunities and advantages.


Let’s start now…
I added two projects to a solution. One for the Desktop-Framework, the other for the .Net Compact Framework.


Both projects had the same default namespace (green boxes) but a different assembly name (red boxes).

This are the properties of the base class:

and this are the properties of the extended class:

At next you need a reference to the base class in the extended class.


When you want to use both classes, the base- and the extended class in an other project you have to create a reference to both classes. Additionally, you have to insert a using-statement in each of the source code files where you want to use it.

Extensions for C#-classes are a fine nice feature. Especially when you could use it over/on different platforms. I used that for my project on