@@ -433,28 +433,69 @@ class CSimpleArray : public std::vector<T> {
433433#define IsEqualIID (a, b ) a==b
434434#define IsEqualCLSID (a, b ) !memcmp(&a, &b, sizeof (GUID ))
435435
436- class CW2A {
437- public:
438- CW2A (const wchar_t *wide, uint32_t utf = 0 ) {
439- (void )utf;
440- size_t len = wcslen (wide) + 1 ; // +1 for '\0'
441- m_psz = (char *) malloc (len * sizeof (char ));
442- wcstombs (m_psz, wide, len);
443- m_psz[len-1 ] = ' \0 ' ;
444- }
445- ~CW2A () {
446- free (m_psz);
436+ template < int t_nBufferLength = 128 >
437+ class CW2AEX
438+ {
439+ public:
440+ CW2AEX ( LPCWSTR psz , UINT nCodePage = CP_UTF8 )
441+ {
442+ if (nCodePage != CP_UTF8 ) {
443+ // you have reached the limits of this half-assed implementation. So sorry.
444+ m_psz = NULL ;
445+ return ;
446+ }
447+
448+ if (!psz) {
449+ m_psz = NULL ;
450+ return ;
451+ }
452+
453+ int len = wcslen (psz)*4 ;
454+ m_psz = new char [len];
455+ std::wcstombs (m_psz, psz, len);
447456 }
448- const char * c_str () const { return m_psz; }
449- operator const char *() const { return m_psz; }
450457
451- public:
458+ ~CW2AEX () { delete [] m_psz; }
459+
460+ operator LPSTR () const { return m_psz; }
461+
452462 char *m_psz;
463+ char m_szBuffer[t_nBufferLength]; // dunno what this is for
464+
465+ };
466+ typedef CW2AEX <> CW2A ;
467+
468+ template < int t_nBufferLength = 128 >
469+ class CA2WEX
470+ {
471+ public:
472+ CA2WEX ( LPCSTR psz, UINT nCodePage = CP_UTF8 )
473+ {
474+ if (nCodePage != CP_UTF8 ) {
475+ // you have reached the limits of this half-assed implementation. So sorry.
476+ m_psz = NULL ;
477+ return ;
478+ }
479+
480+ if (!psz) {
481+ m_psz = NULL ;
482+ return ;
483+ }
484+
485+ int len = strlen (psz) + 1 ;
486+ m_psz = new wchar_t [len];
487+ std::mbstowcs (m_psz, psz, len);
488+ }
489+
490+ ~CA2WEX () { delete [] m_psz; }
491+
492+ operator LPWSTR () const { return m_psz; }
493+
494+ wchar_t *m_psz;
495+ wchar_t m_szBuffer[t_nBufferLength];
453496
454- private:
455- CW2A operator =(const CW2A &) = delete ;
456- CW2A (const CW2A &) = delete ;
457497};
498+ typedef CA2WEX <> CA2W ;
458499
459500template <class T , class Allocator = CAllocator>
460501class CHeapPtrBase
0 commit comments