Extending the .NET Console interface

Although graphical user interfaces are all the rage these days (and rightly so!), there’s still some call for character-mode (console) applications.  In .NET versions 1.0 and 1.1, support for console applications was limited:  sequential access to the standard I/O streams.  .NET 2.0 introduced a much more complete console interface that allows cursor positioning, setting text attributes, and a few other low-level console tricks, but it doesn’t even come close to supporting the full power of the Windows Console API.

My article, Extending the .NET Console Interface, is the first of three planned articles that explore the Windows Console interface and present a .NET class that exposes the entire API to .NET programs.  This first article covers creating and attaching to consoles, responding to console control events, and using console aliases.  The second article will discuss the console screen buffer in detail, and the third will be all about using the console input buffer.  Full source code for the article is available for download here.

Formatting Code the Right Way

If you’ve ever been involved in a large development project, you probably experienced the code formatting nightmare.  How many spaces to indent?  Where does the open brace go?  Should you indent case labels?  There’s little possibility that you’ll convince a group of programmers that your way is best, and invariably you’ll end up with an imposed standard that nobody supports 100%.  Imposing the standard is the easy part.  Enforcing it is something else entirely.

Visual Studio 2005, which will ship when the .NET Framework 2.0 ships, has some pretty impressive code formatting built in to the C# editor.  With it, you can set formatting standards that are enforced automatically as the code is typed.  And you can reformat code almost instantly.  It’s very cool stuff.

I just finished a brief review of these new formatting features.  Check out Formatting Code the Right Way over at DevSource.

A .NET Cabinet file interface

The third and final installment of my article series on reading and writing Microsoft CAB files from .NET is available now on DevSource.  Creating an Object-Oriented Interface to CAB Files describes the CabCompressor and CabDecompressor objects that I created, which wrap the Cabinet SDK functionality in .NET objects and present a familiar .NET event interface to the callbacks.  Full project source code is available from a link at the end of the article.

Accessing Cabinet Files from .NET, Part 2

Just a quick note to say that the second in my three-part series of articles on accessing cabinet files from .NET is available at DevSource.  This article shows how to implement the callback functions and drive the Cabinet SDK functions.

Reading and Writing CAB Files from .NET, Part 1:  Creating a CABINET.DLL Interface

Reading and Writing CAB Files from .NET, Part 2: Using the CABINET.DLL Interface

You can find the code and Visual Studio project files here.

Accessing Cabinet Files from .NET

One of the things that’s kept me busy the last month or so is a project to access Microsoft cabinet files from a .NET program.  I mentioned this in passing before.  It turns out that interfacing with CABINET.DLL from .NET is much more difficult than from C or Pascal, mostly due to calling conventions and string marshaling across the managed/unmanaged layer.

I’m now working on a three-part series of articles on this topic for DevSource.  The first article, Creating a CABINET.DLL Interface, is now available.  To my knowledge (and I looked pretty hard before taking on the project), this is the only published information about accessing cab files from .NET programs.

Writing for publication

I’ve been giving some thought recently to writing and publishing outside of the computer field.  In the 15 years that I’ve been writing, everything I’ve published has been related to computer software.  The only non-computer writing I’ve done is posted on this Web site, which hardly qualifies as “publishing” in my mind.

Publishing outside of the computer industry presents some interesting challenges for me.  Mind you, I have no dearth of material.  I can write about almost anything, and given a bit of time to research I can even write intelligently about most things.  Even finding a place to submit my writing doesn’t pose much of a problem.  A trip to any reasonably well-stocked book store magazine rack proves that it’s possible to publish just about anything.  The problem is getting the acquisition editor’s attention. That’s something I’ve never had to do.

I had several advantages when I started writing about computer programming.  First, I was in daily contact with the editors of major programming journals (Dr. Dobb’s Journal and Computer Language Magazine) on their CompuServe forums.  When I decided on a whim one day in 1988 to put together an article for publication, all I had to do was email a query to Kent Porter, then the technical editor for Dr. Dobb’s Journal. Easy as that, my writing career (such as it is) was started.  At the time, the supply and demand equation was highly in my favor: there were lots of people looking for programming articles and very few programmers who had the desire or ability to write them.  A year or two later I had the good fortune to meet and form a friendship with Jeff Duntemann, who was forming PC Techniques magazine.  The computer publishing business at the time was small and everybody knew everybody else, so if I sent a query to anybody in the business chances were that they knew who I was.  I still had to write good stuff, but with a few writing credits to my name, it was reasonably easy to get a new article published.

By following the simple rule of “always query before writing,” I can honestly say that I’ve never had an article rejected.  I’ve had a few proposals turned down, but every article that I’ve submitted has been published.  Does that mean I’m some great writer?  Not at all.  It just means that I was incredibly fortunate.  I know that there are plenty of very good articles out there by authors who just can’t get an editor’s attention.

Which brings me, in a roundabout way, back to where I started.  How do I get an editor’s attention?  I figured I’d pick up a copy of Writer’s Market (it’s a reference book that lists magazines by topic, how much they pay, who to contact and how, etc.) and find just the right outlet for my article.  And there’s where I got my first rude shock.  How long has email been an essential tool of business?  I’ll be charitable and say five years, although it’s probably closer to ten.  Did you know that much of the publishing industry is still dependent on paper for day-to-day communications?  Many entries in Writer’s Market say something like:

Mail queries to (address).  Allow four weeks for response to queries. Eight weeks for response to unsolicited manuscripts.

The first time I saw that I just shook my head.  After seeing it dozens of times for many major magazines, I hardly could believe it.  They want me to print a letter, put it in an envelope along with a few clips from my portfolio, and mail it?  Four weeks for them to respond to a query?  All they have to do is look at the article proposal, check their editorial calendar and my clips, and decide whether they want me to write the article.  Total time: 7.3 minutes if they go get coffee while they’re thinking about it.  Are they out of their minds?  Why don’t they let me email a query along with links to my clip portfolio?  That would save them (and me!) an incredible amount of time.

It’s a good thing I’m not trying to make a living as a freelance writer of magazine articles.  Just the hassle of printing query letters, attaching clips, and tripping down to the post office would dissuade me from the idea.  It’s bad enough sending an email query and waiting a day or two while the editor digs out from under whatever he’s doing and gets to the email.  Waiting four weeks or more just to find out if the letter got to the editor would drive me insane.  For the time being at least, I’ll limit my queries to magazines that understand how to use electronic mail.  To the others: hire a business consultant and have him drag you kicking and screaming into the 90s.

Writing again

It’s been almost two years since I last published an article.  My article Automatic Memory Management and Unmanaged Resources in .NET appears on the InformIT Web site.  Another article, on .NET Isolated Storage, is scheduled for publication next month.

I’ve also taken over the .NET Reference Guide duties for the site.  As the Guide guy, I’ll post an article in the Reference section, and make three or more Weblog entries each week.  If you’re into programming for .NET, come check it out.  I’m always interested in what other people would like to see covered.

The InformIT site, by the way, is chock full of good stuff:  Reference Guides for Certification, Photoshop, XML, .NET, Linux, Security, C++, Flash, Java, and SQL Server contain a wealth of information that is continually being expanded and updated.  In-depth articles on these and other topics appear weekly, and Weblogs discuss current topics of interest.  The site’s primary purpose, of course, is to sell books, and there are plenty of good books on offer.  Even so, the site provides an incredible amount of useful information for free.

The best deal on the site, though, is the Safari Books Online.  Here you have over 1,500 technical books all online and available instantly for as little as $10.00 per month.  It’s an incredible deal, and well worth the price (even with the restrictions) if your book outlays are anything like mine.

New rant / Dead fig

I posted a new piece on my Rants page.  Not quite a rant, but rather ironic commentary.  I just found out that humor is hard to do well.

I also removed the Fig page.  The fig died last spring when I put it outside and the deer ate it.  Or at least tried to eat it.  Stupid deer pulled it out of the pot and then spit it out.  You’d think they’d at least be smart enough to know that if they don’t like the big fig tree out back, they won’t like the little one up by the house.  Big bony rats.  I think I’ll let a couple of bow hunters on the property next year…

First Anniversary

Wow.  Today I realized that this past Sunday marked the one year anniversary of Jim’s Random Notes.  I guess it doesn’t mean much in the grand scheme of the Universe, but it’s certainly an accomplishment for me.  The first few months it was pretty easy to come up with topics to write about, but after I’d exhausted the stuff on the surface I found that I had to actively search out and study things in order to write anything intelligent here.  Keeping up with this web site on a regular basis has been very good for me.  Just making myself write almost every day has been good discipline, and I think I’ve become a better writer in the process.  Certainly I’ve had to learn how to look at things more critically and also how to succinctly present information that is sometimes overwhelming.  It’s a hugely rewarding exercise that I’d encourage anybody who’s interested to try.