One way is to use assert() - it is either implemented as a macro or a function.

Parksie is right - if the buffer is heap memory, only in Windows the long BEFORE the starting address of the buffer is the size of the buffer. Like BSTR. It's how free() knows how much memory is allocated.

But this is NOT true if the buffer came from OLE or from VB, even if if it allocated memory dynamically like in ReDim. OLE & VB use descriptors in a descriptor table. OLE does use BSTR for string buffers. SO - just check for NULL, maybe in an assert. You cannot depend on anything else.