- if (format == wxDF_UNICODETEXT)
- {
- // host native is UTF16
- wxMBConvUTF16 converter ;
- size_t len = converter.WC2MB( NULL , GetText().c_str() , 0 ) ;
- wxCharBuffer buffer = converter.cWX2MB( GetText().c_str() );
- memcpy( (char*) buf, (const char*) buffer , len + 2); // trailing unichar 0
- }
- else
- {
- wxCharBuffer buffer = wxConvLibc.cWX2MB( GetText().c_str() );
- // in some cases "buffer" is null (e.g. Mac OS X)
- if (buffer)
- strcpy( (char*) buf, (const char*) buffer );
- }
+ if ( buf == NULL )
+ return false;
+
+ wxCharBuffer buffer = GetConv(format).cWX2MB( GetText().c_str() );
+
+ size_t len = GetConv(format).WC2MB( NULL, GetText().c_str(), 0 );
+ len += (format == wxDF_UNICODETEXT ? 2 : 1);
+
+ // trailing (uni)char 0
+ memcpy( (char*)buf, (const char*)buffer, len );