. Home Feedback Contents Search

COM Variables 

Up

COM variables

BSTR

A BSTR is a pointer to an array of 16 bit wide characters. Preceding the wide character array is a count of the number of characters in the array. The character array is supposed to be NULL terminated and the character count is supposed to include this terminating NULL character but there is enough confusion on this in the general programming community at large so that you will need to be careful about these things in your own code.

Converting between MBCS and WCHAR

Variant

A Variant is a general purpose variable. It can be of any type, including arrays. This structure contains a field that indicates what its value type actually is and an area within the structure that is big enough to contain all of the standard data types. If the variant is an array then its data is actually a pointer to memory which actually contains the array of data.

Converting between MBCS and WCHAR

Interface Memory Management

The general rules for COM memory management are pretty simple but depend upon whether the particular item is marked as [IN], [OUT], or [IN,OUT].

In the case of [IN], then the caller allocates the argument and is responsible for freeing it afterwards.

In the case of [OUT], the callee allocates the item but the caller is responsible for releasing it.

In the case of [IN,OUT], the callee normally allocates a value that gets passed to the caller. The caller releases that value and replaces it with a new value which it has allocated. When the COM call returns, the caller then is responsible for what ever came back from the callee.

Up

Hit Counter