Writing Solid Code

My apologies to Steve Maguire for "borrowing" a title. I constantly see code, examples, and advice that perpetuate unsafe coding practices.  As programmers we have the habit of getting something to a "working" state and call it "done".  This is especially true in processes that have no real architecture or design phases.  Over the years, as a society, programmers have begun to realize some of the obvious flaws and have been perpetuating practices and code checkers to avoid such flaws.  But, there's still the mentality of "but it works [in my limited tests], how could it be wrong".  For example, … Continue reading Writing Solid Code

Code Analysis: How to Correctly Resolve CA1300 – "Specify MessageBox Options"

This is the first installment of what I hope to be many short bits of guidance about correctly resolving some of the more complex warnings coming out of FxCop and Code Analysis. The CA1300 warning is specifically about the right-to-left or left-to-right reading order of a message box.  The documentation for the warning alludes that a message box doesn't automatically inherit the containing form's reading order or the reading order from the user's current culture.  Although, I can't find any documentation that confirms either. In any case, this is a rather complex warning to resolve, you possibly have to traverse the form's … Continue reading Code Analysis: How to Correctly Resolve CA1300 – "Specify MessageBox Options"

‘System.Threading.Thread.Suspend()’ is obsolete: ‘Thread.Suspend has been deprecated…

For time eternal there has been a way to suspend (and by association resume) another thread.  It wasn't until .NET 2.0 that someone took leadership and conceded that suspending another thread is not a safe thing to do.  .NET 2.0 deprecates System.Threading.Thread.Suspend() and Resume() (although, Resume() isn't dangerous by association…). Basically, Suspend() has no care that the thread may actually be managing one or more complex invariants that can't be changed atomically.  Normally with complex invariants synchronization is used to ensure while one thread is modifying the individual components of an invariant another thread doesn't try to access it.  This … Continue reading ‘System.Threading.Thread.Suspend()’ is obsolete: ‘Thread.Suspend has been deprecated…

Using Toolbox for Code Snippets in Visual Studio 2005

Just noticed today that you can drag text into the Toolbox then repeatedly drag it back out wherever you want, into a Visual Studio source window. Simply select some text in a source window, drag it over to the Toolbox tab (assuming you have Toolbox set to Auto Hide), wait for Toolbox to expand and drop the text wherever you want it. Now you can simply open up the Toolbox and drag-drop that text whenever you want, much like a code snippet; but much faster (and without literals).

Writing Libraries with Visual C++

Writing libraries of APIs is a very diffcult task on any platform.  There are many things you have to consider during the design of that API, especially with an unmanaged run-time. Visual C++ actually makes it more complicated to build and use libraries. Some rules to evaluate an API you're thinking of using or to help design your APIs: Use the same run-time This may seem obvious just reading it; but it's very complex to use the same run-time.  With Visual C++ 6 there are 6 different versions of the run-time that you have to be careful to match.  There … Continue reading Writing Libraries with Visual C++

Visual Studio 2005 Service Pack 1 Beta

As with any Beta, it's not wise to think of it as "stable" and expect it to work as reliably, or be as tested as an RTM version. But, I've found the second of what I consider blocking issues with SP1 that leads me to think it's time to test the uninstallation.  I independently found that enabling Code Analysis for C/C++ spits out what seems like verbose tracing information that causes Visual C++ to view building with Code Analysis turn on to fail a Build.  I found that someone else had found this already and logged it on Connect: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=218742.  Breaking a … Continue reading Visual Studio 2005 Service Pack 1 Beta

Add Visual Studio 2005 Intermediate Files to Windows Disk Cleanup

A few years ago I remember a small little Code Project project about a Windows Disk Cleanup component that would cleanup VC6 files.  I had always meant to look into that for VS2005 when I had the time. Well, I had a look at the interfaces that the the Disk Cleanup applet uses and it turns out you can add cleanup items to Disk Cleanup without writing a single line of code.  There is a “fallback” cleanup COM component (DataDrivenCleaner) that you can reuse for situations where cleanup can be defined by a directory and/or set of files/wild-cards.  Visual Studio 2005 … Continue reading Add Visual Studio 2005 Intermediate Files to Windows Disk Cleanup