.NET     Console.WriteLine( "All Things .NET" );
.NET Nerd Blog Home
6.30.2003

 
OBJECT tag with PARAM elements
Well, this is not related to .NET at all, but thought it was worthy of blogging here, since they are web and COM related issues.

At work, we recently had to "hijack" a COM component and host it in our own process space. As part of what we did, we could no longer use this from an HTML webpage with the OBJECT tag & PARAM elements like it was originally used. We were now using JScript and new ActiveXObject syntax. Well the question was: how do you set the PARAM elements like we did in the OBJECT tag?

After much investigation, I finally figured out about IPersistPropertyBag and IPropertyBag, along with ATL's treatment and implementation of these interfaces, and how IE (and any other container I guess for that matter) looks for these incoming parameters. (I'm sure I'm highly simplifying this subject, but it's at least good enough for what our needs were...)

At a high level, what I determined that IE and other containers do is the following:
  1. Create an object that implements IPropertyBag, and use it to Write each parameter that you want to set in the object.
  2. Get the IPersistPropertyBag interface from the object, and call Load, passing the IPropertyBag with the values.


ATL implementation
Stuff to be aware of when implementing your IPersistPropertyBag object using ATL. You can derive from IPersistPropertyBagImpl which will do all the work for you.

This implementation uses the PROPERTY MAP entries (see BEGIN_PROP_MAP and friends) to walk your object and see what properties you implement. In the PROP_ENTRY macro, you specify the "name" of the property (as seen by the container, IE html code for example, along with the DISPID of the get/put_propertyXXX methods to access that property. The ATL code will walk the map, and call get/put on each property that it cares about, using Invoke, and the DISPID you put in the macro entry.

I'm probably missing some detail in there, but that's what I remember from a couple days ago when I got this all working.



Powered by Blogger