Re:  Special considerations for Composition (ActiveX controls containing arrays of IDispatch COM objects)?
 
"Siegfried Heintze" <siegfried@heintze.com> wrote in message
news:%23M4wrAEHIHA.3956@TK2MSFTNGP04.phx.gbl
(1)     Does Microsoft office only support controls written in C++ or
can I write them in C#? Last I checked (2005) only IE supported C#
controls.
Office does, and I believe IE does too. See
http://msdn2.microsoft.com/en-us/library/zsfww439.aspx
(2)     I know how to serialize ints and dates for IPropertyBag and
IPersistStreamInit. How do I serialize an array of instances of
descendants of COM Class clip when implementing IPropertyBag and
IPersistStreamInit for ActiveX Class DVD Player?
IPersistStreamInit is simple. Have these objects themselves implement 
IPersistStreamInit. So you would write, say, the number of objects you 
have, then pass the stream to each object in turn to have it save 
itself. When reading, you would read the number of objects, then create 
each one and have it read its state from the stream.
Similarly with IPersistPropertyBag2. You can pass a variant of type 
VT_UNKNOWN or VT_DISPATCH to IPropertyBag2::Write, at which point it 
will turn around, query the object for IPersistPropertyBag2 and ask it 
so save itself. You will have to come up with some naming convention for 
assigning property names to your objects, e.g. Clip0, Clip1 and so on. 
When reading, use IPropertyBag2::LoadObject to have the object load its 
state.
Plain IPropertyBag doesn't have LoadObject method, so the trick above 
only works when your child objects are themselves creatable (have their 
own CLSIDs and can be created with CoCreateInstance). You can use 
IPropertyBag::Write as shown above. When you later call 
IPropertyBag::Read for such a property, it will create an object, 
initialize it using its IPersistPropertyBag interface, and give you the 
new object's interface pointer. Usually though, child objects are not 
creatable so this method can't be used.
As an alternative, implement a pair of private methods on your child 
objects (not necessarily exposed through COM) that accept IPropertyBag 
interface pointer and a prefix to use in property names. The object 
would then save its state as usual, but put a prefix in front of each 
property name it writes. So the first clip would write, say, Clip0_Name, 
Clip0_Start and Clip0_End, the second clip would generate Clip1_Name and 
so on. Similarly for reading.
(3)     How would I implement class clip and its descendants? Since
they need to display themselves inside the C# GUI, is there some GUI
component I could inherit from?
System.Windows.Forms.Control perhaps? Consider asking in a .NET-related 
group.
-- 
With best wishes,
    Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925