Skip to content

2004

Need to dig in unmanaged C++

I am currently working on a project where we have to interact several applicationsĀ (COM, .NET, Linux, Java, etc.) together through a messaging system. One of the applications is a windows application that exposes an application object. In this way we can host it through .NET. The problem is that the application object doesn't expose any events; no exit, close or quit event. What I need to properly close the .NET host.

In contrast to the Win32 SendMessage you can use system hooks to listen to events from any application. But after googling I noticed that .NET doesn't support global hooks! The only way to accomplish, is to make an unmanaged C++ DLL that catches the system hooks, and the .NET DLL will receive them. An example of that can be found on CodeProject Global System Hooks in .NET. Unfortanetly it only receives mouse and keyboard events, so I have to extend it to receive application events.

What code snippet tool are you using?

I think one of the most popular code snippet tools is Code Library for .NET. I don't know how it's with the current version, but all previous versions IĀ tested were very unstable. But it really has all the features I need for a code snippet tool.

I found some other code snippet tools named CodeKeeper.NET and SnippetBox.NET. It's surprising that the two sites are very similar, just search/replace of some text :-). Unfortunately it's not for free.

I wonder what you guys use as code snippet tool...

Declarative versus Imperative programming

Marc Clifton added a nice introduction to declarative versus imperative programming.

Imperative programming (source) Describes computation in terms of a program state and statements that change the program state. Declarative programming (source) Gives the computer a list of instructions to execute in a particular order, declarative programming describes to the computer a set of conditions and lets the computer figure out how to satisfy them

Like Marc Clifton describes in the article, we are already using declarative techniques like resource files, config files, etc. Many libraries like FABRIQ, User Interface Process Application Block for .NET, log4net, etc. uses a XML file to describe a sort of workflow in a declarative way.

Therefore I try to use it where possible on every project. Certainly when it comes to making forms. I just hate the generated code inside the InitializeComponent of a form/control, it is more elegant, readable and maintainable by describing it in a declarative way. For example a menubar would look like this:

 <MENUBARITEM Text="Edit"> 
 <MENUITEMS> 
  <MENUBUTTONITEM Text="Cut" /> 
  <MENUBUTTONITEM Text="Copy" /> 
  <MENUBUTTONITEM Text="Paste" /> 
  ... 

instead of a bunch of statements that are needed for declaration, initialisation, setting properties and to composite the controls together. In this way it is also very hard to see the relationships between the objects!

NewWindow3 event added to WebBrowser control in Windows XP SP2

I've seen on MSDN that the WebBrowser control has a new event in SP2, named NewWindow3 . It's an extension to the NewWindow2 event with additional info in the eventargs. The url that initiates the new window, and the url where the new window is redirecting to.

I am pretty sure that this has something to do with the new popup blocker that will be added in Windows XP SP2.

ie6popsp2a

TechEd 2004, second day

The second day at TechEd I followed 2 sessions about ASP.NET 2.0 where the speaker demonstrated a lot of nice new controls and features. One of the features I like most (call it a feature or a bug-fix), is that the designer does NOT mess your aspx code anymore, which is a very good thing, I think it was called 'HTML preserve'. Features like, themes/skins, a tool for deploying your web application, role based management, navigation control, a bunch of login related controls (registration, login, lost your password, etc.), ...

After that there was the Belgian Day which was very well organized and was really fun (I don't have to mention that a lot of people watched the football :)

TechEd 2004, first day

The first opening key note was very entertaining and refreshing. There was an introduction of the team services in VS.NET, a demo with 3d-glasses on a 64-bit platform, a promising project called SkyServer.org, announce of the Express edition of VS.NET, and many other things.

It's very well organized, everybody at TechEd receives a login where you can check your email, surf on the internet, you receive a bag with a huge set of goodies and documentation, etc.

I just returned from a session of FABRIQ which can be downloaded on GotDotNet and it's a very nice messaging architecture that can be interesting on the project I am currently working on. So, be prepared Tom, Franco and Peter when I come back to Belgium :)

Now we are going to eat something...

greetz from A'dam

Nice little trick for creating typed collections

I found somewhere in the newsgroups a nice trick for creating typed collections. In most of the cases typed collections only differ in the type they get and set.

To make things easier we can do the following. Create an integer collection class, like below:

using System; 
using System.Collections; 
using ItemType = System.Int32;

public class IntCollection : CollectionBase { 

  public void Add(ItemType val) 
  {
    this.List.Add(val); 
  }

  public void Remove(ItemType val) 
  { 
    this.List.Remove(val); 
  }

  public ItemType this[int index] 
  { 
      get { return (ItemType)this.List[index]; } 
      set { this.List[index] = value; } 
  } 
} 

Here we use an alias named ItemType that denote the type that the collection must work with. If we want a collection of the class Employee, we simply copy/paste the IntCollection class and change the class name to EmployeeCollection and set the ItemType to Entities.Employee for example. So we have something like:

using System; 
using System.Collections; 
using ItemType = Entities.Employee;

public class EmployeeCollection: CollectionBase 
{ 
  public void Add(ItemType val) 
  { 
    this.List.Add(val); 
  } 

  public void Remove(ItemType val) 
  { 
    this.List.Remove(val); 
  } 

  public ItemType this[int index] 
  { 
    get { return (ItemType)this.List[index]; } 
    set { this.List[index] = value; } 
  } 
}

Offcourse you can use search and replace, but I found this method more elegant :-)

Initial version of SharpBrowser (finally)

The last couple of weeks I concentrated on writing SharpBrowser. It was already subscribed for a long time on Sourceforge.net, but now I finally released an initial version :-).

The main features of the initial version, is that it is tab-based and it can be used with IE or Mozilla! SharpBrowser uses the great UI library from divil.co.uk for the menus, toolbars, docking and documents. One of the features is that you for example can choose the UI rendering, e.g.: Office2003, Everett and Whidbey.

sharpbrowser1

In order to use Mozilla you just have to download the Mozilla 1.7 ActiveX Control and install it. If the installation is successful you will see an extra menuitem, where you can choose the browser: (left is IE, right is Mozilla)

SharpBrowser3

Note that this is an initial release, and that there a bunch of features that must be implemented. In the following weeks I will concentrate on implementing features that are included in the standard IE and after that extra features like:

  • cookie mamagement
  • download management
  • popup killer
  • google toolbar
  • view partial source
  • event viewer
  • manage broken links
  • mouse gestures
  • plugin-mechanism
  • etc.

That's why I started writing SharpBrowser, because I am convinced that you can implement a set of very usefull features for a browser that are not (yet) included in IE. I am also thinking about features for web developers, like a viewstate decoder, better support for debugging javascript, test scenarios, etc.

This project give me also the opportunity to experiment with libraries like MyXaml, log4net, Microsoft Application Blocks, etc. For me it is important that I can learn of it, and that the project uses the right concepts, design patterns, libraries, etc. That's the reason why I distribute it in open-source so that we can share our knowledge!

In the next couple of days I will explain some concepts that I implemented for SharpBrowser. Patterns like the visitor, command, composite, facade, etc.

If you have any suggestions, ideas for new features, or want to share about good practices, design patterns, libraries, please let me know!

SharpBrowser v0.5

CruiseControl.NET

CruiseControl.NET is a continuous integration tool we have set up for our current project. It automatically builds when there is a change in source control (VSS, CVS, ClearCase, etc), and it reports it in a nice web layout with all the build, nunit, fxcop results.

There is also a nice tray application that can be installed on the developers pc's which indicates the status of the builds, for example it becomes:

  • green: build is successfull
  • yellow: server is currently building
  • red: build is failed
  • gray: server is unavailable

It's always a moment of truth when checking in code and hoping that the tray application remains green :-)

We use NAnt as build tool and NUnit for unit testing. The only thing to pay attention for is that for example deleted files in VSS remains in the working directory and therefore still be included by NAnt. Therefore we setup a small integration server where VSS, Microsoft.NET SDK 1.1 and CruiseControl.NET is installed. The build script that is called by CruiseControl.NET does basically the following tasks:

  • delete all source files
  • get latest version of sources
  • get latest version of buildscripts
  • build the sources
  • test the binaries

(buildscripts, NAnt and NUnit are stored in VSS)

NAnt can do operations on VSS if you download NAntContrib, there you have a set of additional tasks like 'vssget', 'vsslabel', etc. Note that it is a real advantage of storing your buildscripts in VSS so that CruiseControl.NET always uses the latest buildscripts.

RazorToolbox

RazorToolbox is a set of utilities/tools in the form of addins, macros, components, etc. for Visual Studio.NET. In the initial release of RazorToolbox we have ComponentDropper.

In .NET you can easily build components (= also controls), but in order to use them on your designer surface you have to add them in the toolbox of Visual Studio.NET. But there are some problems. For example if you are writing an exe-application and added some components in the exe-project, you cannot add them to the toolbox, because the toolbox only accepts DLLs. Another issue is when you are developing a set of components in a control library, you will have to refresh the toolbox for each component you added in the library, it is not automatically refreshed and is time-consuming. Besides that there are some controls in .NET that are not displayed in the toolbox, for example the PropertyGrid.

ComponentDropper allows you to drop a component on the designer surface from a set of assemblies. For example if you are writing an exe-application and added a usercontrol named UserControl1 like the screennshot below:

componentdropperoverview

Take the ComponentDropper from the toolbox and drag it over the form where you want to drop UserControl1. You get something like:

ComponentDropper

This list gives the set of components that reside in the current project and the assemblies that are referenced in the project. There you can double-click on UserControl1 and it's added to the form.

There are some settings, like you can first build the project before ComponentDropper search for components in the current project. Also you can indicate that ComponentDropper searches in the list of references in the current project. A list of references can be excluded through expressions, for example: System.\*_.

componentdroppersettings

Download: RazorToolbox.zip

Any feedback and comments are greatly appreciated!