musings about technology and software development..

Writing Office client code

Writing Office client code is ... an experience.

First, everything is in unmanaged code, which means each line of code takes 5 minutes to write.  Why?  Because you have to check the APIs every time, to make sure you know who owns the memory and what the exact parameters are.  If you don't, you will get an intermittent AV or corrupt the heap and crash the app.  And, since none of the APIs are documented, you have to go trolling through the sources to figure out what the hell's going on.

Second, you get to use classes with interesting names.  For example, their web service APIs are still called things like HSUser -- long live HailStorm!  Then you've got funny ones like “BpscBulletProof”, obscure ones like “MsoGelIInsertSortPx”, and classes like “MSOGRFXMLNS” (buy a vowel?).

Third, Office has wrappers for almost everything.  I started by writing everything in standard C/C++, and it all worked beautifully.  But that was a big mistake, because none of it worked once I tried to merge it into the code depot.  I wasted the better part of a week translating ATLSoap to CBaseHSUser, vector to MSOPX, CMap to LKRHash, RegQueryEx to MsoRegReadWz, CString to CMsoString, and the list goes on. 

Fourth, the wrappers are actually pretty neat -- until you have to debug one.  Good luck figuring out what the author's intention was for “const WCHAR* const *rgwzArg” or “MSOPFNSGNPX pfnSgn” (I couldn't make that up even if I tried).  The time I saved using a “convenient wrapper” is quickly negated by having to figure out why my memory keeps getting wiped out.  It's like that movie Memento, but with a lot more swearing.

I think that's enough ranting for one post, back to work.


Post a Comment