April 01, 2003
Tech Tips
Listing 1 Safe wrapper for constructing a temp file path
// Safe wrapper for constructing temp file path, using ATL's CComBSTR
// for help with memory mgmt.
//
static long SafeGetTempPath( BSTR* resultP)
{
// Always initialize [out] params, early on
*resultP = 0;
// Query for the size, and allocate buffer via SysAllocStringLen
DWORD numCharsReqd = ::GetTempPath( 0, 0);
ATL::CComBSTR temp( (numCharsReqd-1));
// note: SysAllocStringLen will tack on space for a null-term char
// Now actually query for the temp path
if ( !::GetTempPathW( numCharsReqd, temp.m_str))
return ::GetLastError( );
// Done
*resultP = temp.Detach( );
return 0;//ok
}
|
|
||||||||||||||||||||||||||||
|
|