Pointer Validation Macros


Microsoft® DirectShow™ provides some macros to make pointer usage more robust. These include a simple CheckPointer macro (which tests if a given pointer is NULL). These also include a number of ValidateXxxPtr macros, which ensure a given pointer actually refers to the correct kind of memory, although possibly with a significant performance hit for each test.
Name Description
CheckPointer Checks whether or not a given pointer is NULL.
ValidateReadPtr Validates a read pointer.
ValidateReadWritePtr Validates a read/write pointer.
ValidateStringPtr Validates a string pointer.
ValidateStringPtrA Validates an ANSI string pointer.
ValidateStringPtrW Validates a wide (Unicode) string pointer.
ValidateWritePtr Validates a write pointer.


CheckPointer

Determines if a given pointer is NULL. If the pointer is NULL, CheckPointer returns a user-defined value.

CheckPointer(
  p,
  ret
  );

Parameters
p
Pointer to check.
ret
Value your function will return if p is NULL.
Remarks

The following examples illustrate how to call this macro.


HRESULT OneFunction(VOID *pSomeParameter)
{
    CheckPointer(pSomeParameter, E_INVALIDARG)
}

BOOL AnotherFunction(VOID *pSomeParameter)
{
    CheckPointer(pSomeParameter, FALSE)
}


ValidateReadPtr

Checks a read pointer. If the pointer is not valid, this macro calls DbgBreak.

ValidateReadPtr(
  const void * p,
  UINT cb
  );

Parameters
p
Pointer value (of any type).
cb
Byte count to be checked.
Remarks

This macro is ignored unless DEBUG or VFWROBUST is defined when the Microsoft DirectShow headers are included.


ValidateReadWritePtr

Checks a read/write pointer. If the pointer is not valid, this macro calls DbgBreak.

ValidateReadWritePtr(
  const void * p,
  UINT cb
  );

Parameters
p
Pointer value (of any type).
cb
Byte count to be checked.
Remarks

This macro is ignored unless DEBUG or VFWROBUST is defined when the Microsoft DirectShow headers are included.


ValidateStringPtr

Checks a string pointer and calls DbgBreak if the pointer is not valid.

ValidateStringPtr(
  LPCTSTR p
  );

Parameters
p
TCHAR string pointer value.
Remarks

This macro is ignored unless DEBUG or VFWROBUST is defined when the Microsoft DirectShow headers are included.


ValidateStringPtrA

Checks an ANSI string pointer and calls DbgBreak if the pointer is not valid.

ValidateStringPtrA(
  LPCSTR p
  );

Parameters
p
ANSI string pointer value.
Remarks

This macro is ignored unless DEBUG or VFWROBUST is defined when the Microsoft DirectShow headers are included.


ValidateStringPtrW

Checks a wide (Unicode) string pointer and calls DbgBreak if the pointer is not valid.

ValidateStringPtrW(
  LPCWSTR p
  );

Parameters
p
Wide string pointer value.
Remarks

This macro is ignored unless DEBUG or VFWROBUST is defined when the Microsoft DirectShow headers are included.


ValidateWritePtr

Checks a write pointer and calls DbgBreak if the pointer is not valid.

ValidateWritePtr(
  const void * p,
  UINT cb
  );

Parameters
p
Pointer value (of any type).
cb
Byte count to be checked.
Remarks

This macro is ignored unless DEBUG or VFWROBUST is defined when the Microsoft DirectShow headers are included.

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