I've found CComDatereally useful but when I compile I get a warning that wcscpy may be unsafe and I should use wcscpy_s
e.g.
LPTSTR CComDATE::Format(LPTSTR pszOut, DWORD dwFlags, LCID lcid) const { *pszOut = 0; // If invalild, return empty string if (!IsValid()) return pszOut; BSTR bstr = 0; if( SUCCEEDED(VarBstrFromDate(m_date, lcid, dwFlags, &bstr)) ) { #ifdef _UNICODE wcscpy(pszOut, bstr); #else wcstombs(pszOut, bstr, wcslen(bstr) + 1); #endif SysFreeString(bstr); } return pszOut; }
but because this is using BSTR I'm unsure about the correct "numberOfElements" in
errno_t wcscpy_s( wchar_t *strDestination, size_t numberOfElements, const wchar_t *strSource );
is it something like sizeof(DWORD) + ( _wcslen(bstr) + 1 ) * sizeof(WCHAR)?