FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Dobbs M-Dev
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
April 01, 2003

Tech Tips

(Page 2 of 3)
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 
} 

Previous Page | 1 | 2 | 3 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK