Random Post: DRM I'm Content With
RSS .92| RSS 2.0| ATOM 0.3
  • Home
  • About
  • Eric’s Toolset
  • Free Software
  • Software License
  •  

    Corrupt docx File After Adding Custom Properties Part

    March 14th, 2008

    I spent a few days implementing a component that adds some custom properties to Office 2007 files. Using the System.IO.Packaging namespace from .NET 3.0, and looking at some sample code in some Visual Studio snippets, things went pretty smoothly. Just when I thought I was done, though, I tried opening a manipulated .docx file in Word and got the message “The file is corrupt and cannot be opened.”

    Read the rest of this entry »


    .NET Cold Startup Performance: An Example

    March 6th, 2008

    When running a .NET application for the first time after rebooting or hibernating the computer, you might find that it takes a long time to start up. I’ve been trying to address this problem in a few situations recently. In spite of having read several articles on the subject, I wasn’t having much success. Following some of the advice gave no noticeable improvement, and some (like using NGEN) actually slowed down startup. But I had some success recently, so I thought I’d explain how.

    Read the rest of this entry »


    Converting from Visual Studio 2005 to Visual Studio 2008

    February 15th, 2008

    I’ve just finished switching over our development environment from Visual Studio 2005 to Visual Studio 2008 (except for a C++ solution that uses boost, which will take some further effort). These are the things that I needed to do, and the gotchas I encountered.

    Read the rest of this entry »


    Automatic Test Cleanup in VS 2008

    February 14th, 2008

    I’m working on switching from VS 2005 to VS 2008. I just tried running some unit tests and got the following dialog:

    clean-up-tests.jpg

    Hooray! I’ve been trying to figure out how to implement automatic test cleanup myself, but I (fortunately) hadn’t had time to devote serious effort to it. Up to this point, the TestResults directory would just continue to grow and grow until you either went in deleted the directory or ran an Ant target we have for ensuring any testing left-overs get mopped up.


    Getting the Host’s Main Window Handle in an Office Add-in

    January 23rd, 2008

    Sometimes you want the window handle of the host application when you’re writing an Office add-in. Excel includes that as a property of the Application object in newer versions of the object model, but Word and PowerPoint don’t. I seem to remember some sample code from Microsoft that suggests using FindWindow to get the handle, but that always seems problematic:

    • You can search by class name (e.g. “OpusApp” for Word), but what if you somehow have multiple Word processes running? Which window do you get?
    • You can search by window text, but it can be really hard to figure out what the window text is.
    • You can set the Caption property on the Application object to some magic text and search for a window with the magic text, but Word throws all kinds of other stuff into the caption so this generally doesn’t work reliably.

    Instead, if you’re using managed code, you can just do this:

    IntPtr hwnd = Process.GetCurrentProcess().MainWindowHandle;

    Underneath this uses EnumWindows and GetWindowThreadProcessId to find the right window.