- if (format == wxDF_UNICODETEXT)
- {
- // host native is UTF16
- wxMBConvUTF16BE converter ;
- wxCharBuffer buffer = converter.cWX2MB( GetText().c_str() );
- strcpy( (char*) buf, (const char*) buffer );
- }
- else
- {
- wxCharBuffer buffer = wxConvLibc.cWX2MB( GetText().c_str() );
- strcpy( (char*) buf, (const char*) buffer );
- }
-
- return TRUE;
+ 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 );
+
+ return true;