AddProp

HRESULT AddProp(
const WCHAR* wszName, 
VARTYPE vtType, 
long lOffset, 
void *pDefValue);

Parameters

wszName

Pointer to the property name, used for PropertyBag persisting. This pointer must be constant data and must not change during the lifetime of the object.

wtType

Variant data type of the property. The following property types are supported.

Property type Description
VT_BOOL Use for properties of VARIANT_BOOL.
VT_I2 Use for numeric properties of type short.
VT_I4 Use for numeric properties of type long or integer.
VT_R4 Use for numeric properties of type float.
VT_R8 Use for numeric properties of type double.
VT_LPWSTR Use for wide string properties.
VT_LPSTR Use for ANSI/multibyte string properties.
VT_BSTR Use for BSTR string properties (Basic strings).
VT_UNKNOWN Use for interface properties that support IPersistStream and IPersistPropertyBag and are co-creatable. For example, IFont and IPicture are interfaces that meet these requirements.

lOffset

Offset to property in the user data buffer. This is unique among the properties. If a property is already added with the same offset, then the latter add will replace the former.

pDefValue

The default value of the property. Properties are not persisted if the current value matches the default value. Depending on the property data type, this argument is interpreted as follows.

Property type Description
VT_BOOL Pointer to VARIANT_BOOL; the value is copied.
VT_I2 Pointer to a short; the value is copied.
VT_I4 Pointer to a long; the value is copied.
VT_R4 Pointer to a float; the value is copied.
VT_R8 Pointer to a double; the value is copied.
VT_LPWSTR Pointer to the string data; the pointer is stored and referenced as needed.
VT_LPSTR Pointer to the string data; the pointer is stored and referenced as needed.
VT_BSTR Pointer to the string data; the pointer is stored and referenced as needed.
VT_UNKNOWN Pointer to a CLSID; the pointer is stored and referenced as needed.

Returns

S_OK

Method succeeded.

E_OUTOFMEMORY
Returned if allocation failed.

E_INVALIDARG
Returned if the Variant type is not supported.

Comments

Adds a property to the persistence collection.

For VT_UNKNOWN, pDefValue must point to an IID for the interface object. After a load, the IUnknown is QI for the interface identified by the given IID, and is stored at the specified offset in the user buffer.

Property offsets are offsets within a contiguous buffer kept by the caller. A property offset can be an offset to a data member within a class or a data member within a structure. Regardless, for each CPersistProperties collection, the offsets must be within the same buffer. The buffer and the buffer size are passed to the Load and Save methods for persistence.