Thursday, May 15, 2008

OLE out-of-process server in C#

I am trying to build an out-of-process OLE server using C# (VS 2005) for linking and embedding into Office applications. Current source code is here. It works, but see README.txt.

Each "box" has a name, a comment and draws itself as a square in the available rectangle with a red cross that helps you see whether it has been truncated. The box can render itself as an embedded object, an enhanced metafile, an old-style Win16 metafile, a device-independent bitmap, and a device-dependent bitmap (HBITMAP). See BoxRenderer.cs. It includes the name of the rendering format in the top left.

The best resource I have been able to find is Kraig Brockschmidt's Inside OLE (2nd ed; ISBN 1-55615-843-2), published back in the mid-nineties. My copy did not include the original CD, but Kraig very kindly sent them to me. (They are supposed to be on the Microsoft website, but this was broken at the time of writing.) Microsoft seems to have fallen out of love with OLE and provides little useful information besides the API references.

Implementation Notes (but more in the source code comments):
  • I am only implementing existing OLE interfaces so I did not want regasm, type libraries, etc.
  • The COM layer in .Net seems to call me from a pool of threads, so I have had to be quite careful with thread safety. I would love to know if there is a way to control the threading model.
  • This is code is certainly more complicated than I had hoped, and a lot of this stuff has been pasted together from Google and guesses so please do tell me if you see anything stupid or can see a way it can be simplified. Error handling is also haphazard.
It appears that each Office application has implemented OLE separately, as each has its own distinct quirks.
Microsoft Word:
  • Well behaved, in my view.
  • Always displays ye olde Win16 metafiles.
Microsoft Excel:
  • Shows the enhanced (Win32) metafile rendering when first pasted in, but then switches to old Win16 metafiles when I resize the box. I think this is because it has called IDataObject.DAdvise requesting CF_METAFILEPICT - perhaps for backward compatibility - and thus that is what it is given we we tell its IAdviseSink of changes. Note that when it an Excel file containing a Box it asks (and shows) CF_ENHMETAFILE at all times.
  • Stretching and rescaling within Excel works fine, and will be pass on to the Box object. But, see below.
  • Resizing via BoxForm works fine, and will be reflected within Excel, so long as you have not first stretched the box using Excel. (Scaling is OK.)
  • Cross-hash lines won't go away when BoxForm is closed??? Maybe we should be putting ourselves in the running object table? (Same for Visio.)
  • Not drawing linked objects.
Microsoft PowerPoint:
  • Resizing within PowerPoint (whether stretching or scaling) is not passed on to the Box object. Instead PowerPoint scales the metafile. But, see below.
  • Resizing via BoxForm works fine, and will be reflected within PowerPoint, so long as you have not first resized the box using PowerPoint.


Anonymous Anonymous said...

Hey I would LOVE to see the updated version!!! Please can you post it!

also pls add a note in yr readme that you need to update the paths in the .reg file



4:47 pm  
Blogger Oliver Bock said...

Just updated the ZIP file. I don't think the .reg file is needed anymore.

5:01 pm  
Blogger Milind Contractor said...

Hi Oliver,

I got the code but i want to render the other object like button, Option Button, Check box etc. which i can see on the powerpoint slide and run the form as is when i make the changes on the form.


2:59 am  
Blogger Unknown said...

Se você esta pensando em comprar sementes de maconha e pensando em sementes de Paradise seeds, visite a loja Shayana shop oferece uma grande variedade de sementes de maconha, incluindo os bancos de sementes HQ seeds, Dutch Passion seeds, Dinafem seeds e muitos outros a ótimos preços.

9:21 am  

Post a Comment

<< Home