Article ID: 108934
Article Last Modified on 12/3/2003
APPLIES TO
- Microsoft OLE 2.01
- Microsoft OLE 4.0, when used with:
- Microsoft Windows NT 4.0
- Microsoft Windows NT 3.51 Service Pack 5
- Microsoft Windows NT 4.0
- Microsoft Windows 95
- Microsoft Windows 2000 Standard Edition
This article was previously published under Q108934
SUMMARY
The callee frees a BSTR passed in as a by-reference parameter before assigning the parameter a new value. In all other cases, the caller frees the BSTR.
MORE INFORMATION
OLE Automation defines the BSTR data type to handle strings that are allocated by one component and freed by another. The rule for freeing a BSTR is as follows:
The callee frees a BSTR passed in as a by-reference parameter before assigning the parameter a new value. In all other cases, the caller frees the BSTR.
In other words, the caller handles BSTRs as follows:
- Free BSTR returned by called function or returned through a by- reference parameter of called function.
- Free BSTR passed as a by-value parameter to a function.
The callee handles BSTRs as follows:
- Free BSTR passed in as a by-reference parameter before assigning a new value to the parameter. Do not free if a new value is not assigned to the by-reference parameter.
- Do not free BSTR passed in as a by-value parameter.
- Do not free BSTR that has been returned to caller.
- If a BSTR passed in by the caller is to be stored by the callee, store a copy using SysAllocString(). The caller will release the BSTR that it passed in.
- If a stored BSTR is to be returned, return a copy of the BSTR. The caller will release the BSTR that is returned.
Additional query words: 2.01 3.50 4.00
Keywords: kbprogramming kbautomation KB108934