Vista, run as admin and drag and drop on Forms

It appears that you can’t drag and drop onto a windows forms application if it’s being run as admin.  Since you are advised to run Visual Studio on Vista as admin that means that running it with the debugger means you won’t be able to see your drag drop functionality.  I really need to investigate why.  Having said that knowing that’s the case means I no longer have to waste time wondering why my code doesn’t work!

Internet Explorer and Foreign Languages

Internet Explorer is pretty good at displaying foreign languages. There are several mechanisms for displaying languages that have different character sets to our own.

The most portable two for web browsers are UTF-8 and normal ASCII.

ASCII Character Sets

If you want to use a different code page you simply specify the character set, to specify the Russian code page use the following meta tag,

It is worth noting that you should always specify a character set for your pages. Never assume that a page will be interpreted with the standard character set. If it is just the normal latin one set the charset to iso-8859-1

For more information about characters sets a good resource is

Unicode Character Sets

Unicode is a single character set; it defines a unique character for every character in every language. At least that’s the idea. I understand that they are still defining some of the characters from obscure medieval languages but most of our current ones have their characters in place already. This is so that we do not have to flip code pages to display different languages, we can just use the same character set throughout the whole application and it will have Russian characters, Chinese, and even good old Latin characters.

The bit when most people start to get confused is when we talk about how many bytes we use to represent. I did so myself until I had spent quite a lot of time looking at the issue. On windows we have ‘Wide’ characters, which are Unicode. These are stored in 16-bits. This gives rise to the impression that Unicode characters are stored in 16 bits. You then come across UTF-8 being used in web browsers and things start to get murkier. These are simply different representations of the Unicode character set. The UTF stands for Unicode Transformation Format. These are simply alternative representations of the Unicode character set. The representation used by Windows in NT is UCS-2, a 16 bit representation only able to access the first 16-bits of the Unicode character set. This isn’t too much of a problem right now as there are no languages defined outside this space yet.

UTF-8 encodes the Unicode character set as a varying number of bytes. The one quirk that makes it so loveable is that the 7-bit US-ASCII characters are represented by the 7-bit ASCII values. In other words your Standard English text is not encoded any differently in UTF-8 to how it is currently in ASCII.

If you want to specify UTF-8 text use this meta tag.

For a lot more detailed information go to

My first open source project

I created my first full open source project last summer.  While going to the Perl conference and before I found someone to tell me the module that did what I needed (Date::Manip) I created a library for converting a string to a date.  It’s really simple and already done everywhere else but I wanted it for use in a commercial project to make some UI more attractive.  The module is up on google code at

It’s not the only open source project I’ve contributed to but it’s my first where I own it.  Not that anyone should actually use it.  I just wanted to make sure I had the code available when I wanted something quick and simple to use.

One other interesting project I contributed some code to is the heme project –  It’s a simple hex editor for *nix.

The google code project hosting and sourceforge are both fine.  Google seems to be more lightweight but they do keep adding features.  When I first put up my project there was bug tracking and subversion.  Now there’s some wiki stuff and downloads.  If you use gmail then the google offering is pretty neat because you don’t need another login.

Problems compiling VO applications because executable is too big.

If you discover problems compiling your application then there is a setting for the maximum size of the binary being created. The registry key is HKEY_CURRENT_USER\Software\ComputerAssociates\CA-Visual Objects 2.5\VOLink
Create the value BinarySize, this specifies the largest size of executable that VO will allow you to compile. Typical values are, 0x4000000 (64mb) and 0x8000000 (128mb).

If you want to change the setting on VO 2.7 then edit the config file and add or edit the section VOLink.


Automating FTP on the cheap

All windows 2000 and above computers come with quite a decent selection of tools for automating processes. It is quite trivial for example to backup or copy date to a remote computer using ftp with the exisitng command line tools. By writing your ftp commands to a file and reading this using ftp you can remove the need for human intervention completely.

An example script follows,

Upload file,

@echo off
echo open server > %TEMP%\ftpscript
echo user username password >> %TEMP%\ftpscript
echo bin >> %TEMP%\ftpscript
echo put >> %TEMP%\ftpscript
echo put >> %TEMP%\ftpscript
echo put >> %TEMP%\ftpscript
echo put >> %TEMP%\ftpscript
echo bye >> %TEMP%\ftpscript
echo. >> %TEMP%\ftpscript
ftp -n -i < %TEMP%\ftpscript

This is a very simple script that creates the script it uses on the fly. Use the scheduler (accessable via the computer settings option) to add the script to it and you have an automated file copy.

Note: one of the things you need to be careful about is who has permission to the scripts and temp files. The script must have the username and password in it.

Finding syscalls on Linux

In order to find out about the syscalls in linux you can use quite a few sources. There are a few websites summarising the details quite nicely, one of these is

Alternatively if you have the kernel source you can look in the following files,


Or for a more low tech solution when nothing else is available you can dissassemble the C library binary. You should be able to deduce the syscalls and their meanings from this.

objdump -S libc.a

Setting up a daemon on Debian

Debian comes along with a nifty little script to add all the symbolic links you need to the /etc/rc.* directories. Run the following,

/usr/sbin/update-rc.d mysql.server defaults 99

This will create the links starting [K|S]99mysql.server in the relevant directories. Do a man update-rc.d to find out more about it.

This would appear to be possible on Ubuntu aswell since it came from Debian.

Resizing arrays in C

It’s not possible to resize arrays allocated on the stack. Well not in any orthodox way. The only real way to do it is with stuff allocated on the heap. You can use realloc or do it manually yourself and use malloc.

One useful thing that might make you think there were resizeable strings though is being able to specify an array without specifying it’s dimension. The thing is that you do that while specifying it’s contents. For example,

char mystring[] = "hello";

That creates a string on the stack with enough memory for the “hello” string and puts that into it.

That’s different to char *mystring = "hello"; because you actually have memory allocated on the stack for that first example. That means that unlike the char * you can write to the memory.

Of course just because you’ve sized an array doesn’t mean it has to be that size. A trick one of my friends came up with was creating a struct with a 1 char array at the end. He would then cast that to a block of memory and use that as the way to access the rest of the block of memory.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct pascal_string
        int length;
        char c_str[1];
} pascal_string;

pascal_string *new_string(int length, char *value)
        pascal_string *str = (pascal_string*) malloc((sizeof(char)*length)+sizeof(struct pascal_string));
        // allocates one extra char so that it can store the null 
        // and have the string both C style and Pascal style.
        str->length = length;
        memcpy(str->c_str, value, length*sizeof(char));
        str->c_str[length] = ‘’;
        return str;

void main()
        char test[3] = { ‘a’, ‘b’, ‘c’ };
        pascal_string *str;

        str = new_string(3, test);
        printf(“%d : %s\n”, str->length, str->c_str);

This is a really contrived example but as you can see you can overlay the struct over the memory and it allows you to make the most of the compiler. You don’t need to have a char * that you need to set to be a pointer to the memory. References to the array will already be pointing to the correct place.

The reason he liked it so much is that he was able to load chunks of files and overlay that struct to allow him to manage whole chunks at a time in a single block of memory.