- 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;
+ wxCharBuffer buffer = GetConv(format).cWX2MB( GetText().c_str() );
+ if ( !buffer )
+ return false;
+
+ size_t len = GetConv(format).WC2MB( NULL , GetText().c_str() , 0 )
+ + ( format == wxDF_UNICODETEXT ? 2 : 1 ) ;
+
+ memcpy( (char*) buf, (const char*) buffer , len ); // trailing (uni)char 0
+
+ return true;