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.
CheckPointer | Checks whether 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. |
Determines if a given pointer is NULL. If the pointer is NULL, CheckPointer returns a user-defined value.
Syntax
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) }
Checks a read pointer. If the pointer is not valid, this macro calls DbgBreak.
Syntax
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 DirectShow headers are included.
Checks a read/write pointer. If the pointer is not valid, this macro calls DbgBreak.
Syntax
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 DirectShow headers are included.
Checks a string pointer and calls DbgBreak if the pointer is not valid.
Syntax
ValidateStringPtr(
LPCTSTR p
);
Parameters
- p
- TCHAR string pointer value.
Remarks
This macro is ignored unless DEBUG or VFWROBUST is defined when the DirectShow headers are included.
Checks an ANSI string pointer and calls DbgBreak if the pointer is not valid.
Syntax
ValidateStringPtrA(
LPCSTR p
);
Parameters
- p
- ANSI string pointer value.
Remarks
This macro is ignored unless DEBUG or VFWROBUST is defined when the DirectShow headers are included.
Checks a wide (Unicode) string pointer and calls DbgBreak if the pointer is not valid.
Syntax
ValidateStringPtrW(
LPCWSTR p
);
Parameters
- p
- Wide string pointer value.
Remarks
This macro is ignored unless DEBUG or VFWROBUST is defined when the DirectShow headers are included.
Checks a write pointer and calls DbgBreak if the pointer is not valid.
Syntax
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 DirectShow headers are included.
Top of Page
© 2000 Microsoft and/or its suppliers. All rights reserved. Terms of Use.