BSTR Functions


The Wxutil.h header file in the Microsoft® DirectShow™ base classes provides helper functions for allocating and freeing task-allocated BSTR strings.
Function Description
FreeBSTR Frees the task-allocated BSTR string.
WriteBSTR Creates a task-allocated BSTR string by allocating task-allocated memory and copying a wide string to it.


FreeBSTR

Frees a task-allocated BSTR string from memory.

STDAPI FreeBSTR(
  BSTR* pstr
  );

Parameters
pstr
Address of the BSTR to free.
Return Values

Returns S_OK if successful, or S_FALSE if pstr is null.

Remarks

Memory is allocated for passing between objects across interfaces by calling CoTaskMemAlloc. It is freed by calling CoTaskMemFree. You can allocate, pass, and free memory safely between objects created in different programming languages by using a central memory allocator.


WriteBSTR

Allocates and fills a task-allocated BSTR string.

STDAPI WriteBSTR(
  BSTR* pstrDest,
  LPCWSTR szSrc
  );

Parameters
pstrDest
Pointer to where the address of the allocated BSTR will be stored.
szSrc
Wide (Unicode) string that will be copied to the newly allocated BSTR string.
Return Values

Returns an HRESULT value.

Remarks

Memory is allocated for passing between objects across interfaces by calling CoTaskMemAlloc. It is freed by calling CoTaskMemFree. By using a central memory allocator, memory can be allocated, passed, and freed safely between objects created in different programming languages.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.