Threads and mutexes went in cleanly, thanks for all your help! Next up -- i18n. I'd like to convert between UTF-8 and UTF-16 using the "apr_xlate_conv_buffer( )" function, but I can't get it to produce useful data. Does anyone see what Iâm doing wrong? The following code compiles, links, and runs fine (Visual Studio .NET 2003), but doesn't produce the correct output:
# // Main.cpp # #include <string> # using namespace std; # #include "apr.h" # #include "apr_general.h" # #include "apr_xlate.h" # # // main # int main( int argc, char const* const* argv ) # { # // Start APR # apr_app_initialize( &argc, &argv, 0 ); # # // Create an APR pool and xlate converter # apr_pool_t* pool = 0; # apr_xlate_t* xlate = 0; # apr_pool_create( &pool, 0 ); # apr_xlate_open( &xlate, "utf-8", "utf-16", pool ); # # // Prepare the source UTF-16 string # wstring utf16String = L"Hello world!"; # const char* utf16Buffer = (char*)utf16String.c_str( ); # apr_size_t utf16Length = utf16String.size( ) * 2; # # // Prepare the destination UTF-8 string # string utf8String; # utf8String.resize( utf16Length ); # char* utf8Buffer = (char*)utf8String.c_str( ); # apr_size_t utf8Length = utf8String.size( ); # # // Do the conversion # apr_xlate_conv_buffer( xlate, utf16Buffer, &utf16Length, utf8Buffer, &utf8Length ); # utf8String.resize( utf8String.size( ) - utf8Length ); # apr_xlate_close( xlate ); # # // Done # apr_terminate( ); # return 0; # } I'm not checking return values here for brevity of example, but they all return success with one exception: "apr_xlate_conv_buffer( )". "apr_xlate_conv_buffer( )" returns "70008", which I'm assuming has something to do with buffer overflow, though I donât know how to convert into a real error message. "utf16Length" starts out as "24", and ends at "8". "utf8Length" starts at "24", and ends at "0". So far as I can tell, this means it's only consuming 2/3 of the input buffer, but overflowing the output buffer (which is the likely cause of the error return value). The final value of "utf8String" is: "à âÃââÃÂâÃÂâÃÂâÃââÃÅâÃÂâ" (ie, a bunch of gibberish characters, if it's stripped from the email) Any ideas what I'm doing wrong? -david