Thursday, 5 March 2009

Version Control

Version control is a vitally important part of software development. But really, who wants to get it all set up for small projects?

Well this is the age of free/cheap hosting. I have a wonderful solution going. I am using Unfuddle.com for free SVN hosting and AnkhSVN as the version control provider for Visual Studio 2008. It's a great combination. AnkhSVN integrates seamlessly into Visual Studio. As an added bonus, Unfuddle provides a defect ticket system.

C# interop

C# interop with unmanaged code is not nearly as difficult in practice as it sounds on paper. Most of the interop I have done has been COM (to/from managed code) but for my current freelance gig I need to call from C# into an ANSI C DLL.

I wrote a few simple ANSI C functions to act as the interface to my managed code, just to save some work. I could call them fine. Crucially, I could pass in ANSI strings and get them back.

Then I started getting an AccessViolationException "Attempted to read or write protected memory". I was positive that I had annotated the ANSI C code correctly to export the functions. The C# code had the appropriate DllImport decorations. C# and ANSI C thought the function was CDECL. Everything looked just fine.

The symptoms were downright peculiar. If I declared a local variable in the ANSI C function that I was calling the code threw the exception. If I attempted to call another function from inside the ANSI C function the code threw the exception.

As with so many things, it boiled down to an incorrect setting in the project file, a residual glitch from the fact that I first produced an EXE to exercise the code and then flipped to producing a DLL.

Along the way I learned that I don't need to mess about with IntPtr allocation and freeing. When I have a mutable string (e.g. the result is returned in a char* parameter), I can create a StringBuilder with the appropriate size and pass that from C#. C# marshals it for me.

Sunday, 1 March 2009

Rebuilding machines

This past month has been the month of installing stuff. My wife's hard drive crashed. I managed to resuscitate it enough to pull most data off, then dropped a new drive in. I got a new laptop (an insurance replacement for the laptop that got stolen from our house) and had to set that up. Then serious issues with my primary machine. I am now freelancing. None of this is billable time of course.

My primary machine is a seven (!) year old Dell. It has served me well. Lately I have had difficulty installing software, especially some Windows Updates and Visual Studio 2008. The errors have never been very helpful but in the event logs I could see recurring errors with the Cryptographic Provider Service not being able to start. The error is simply "error: 193".

It seems that people had big issues with the Cryptographic Service in 2003-2004 associated with some service packs, but none of the solutions from that time (deleting corrupt databases so it would rebuild them, checking your "Trusted Root Certification Authorities") made a bit of difference.

In the end I reinstalled the Windows XP Pro, then all my usual applications, then various service packs (SP3 can't be installed without a prior SP; SP1 is not available; SP2 can be installed without anything prior), drivers from Dell etc.

This past month has blown out our data caps several times. New Zealand ISPs charge by data throughput. We have a 5Gb per month allocation. This past month we used 14Gb. Of course, downloading a 1.7Gb IDE for iPhone development didn't help.