Platform SDK: MAPI |
The need to validate object pointers arises when calls are made to retrieve MAPI objects or when private method calls are made within your client or service provider. It is always a good idea to validate these pointers. However, unlike parameter validation, MAPI does not provide a single API function to use. Instead there is a recommended series of steps to ensure that object pointers given to your client or service provider are valid. Not all steps are appropriate for all situations; the vtable verification step, for example, is unnecessary in C++.
To validate object pointers
MAPI provides two API functions for validating pointer memory: IsBadWritePtr and IsBadReadPtr. The following C code sample illustrates how to validate an object pointer using all of the steps outlined above and these two API functions.
if (IsBadWritePtr(lpMyObject, sizeof(MYOBJECT))) return failure if (IsBadReadPtr(lpMyObject->lpVtbl, size(MYOBJECT_Vtbl))) return failure if (lpMyObject->lpVtbl->SetProps != MYOBJECT_SetProps) return failure if (lpMyObject-> cRef == 0) return failure