tpl を使用して、wchar_t* 文字列を含む構造体をシリアル化しようとしています。
私が持っているコードは次のようになりますが、機能していません:
#include <stdio.h>
#include <locale.h>
#include <string.h>
#include <wchar.h>
#include "tpl.h"
struct chinese_t {
wchar_t *chars;
};
int main() {
tpl_node *tn;
struct chinese_t cstr;
cstr.chars = L"字符串";
tn = tpl_map("S(s)", &cstr);
tpl_pack( tn, 0 );
tpl_dump(tn, TPL_FILE, "string.tpl");
tpl_free(tn);
struct chinese_t cstr2;
tn = tpl_map( "S(s)", &cstr2);
//tpl_load(tn, TPL_MEM, buffer, len);
tpl_load(tn, TPL_FILE, "string.tpl");
tpl_unpack(tn, 0);
tpl_free(tn);
printf("%ls\n", cstr2.chars);
return;
}
中国語の「字符串」文字列を「1234」に置き換えると、「1」が出力されるだけです-構造体がchar *を使用するように定義を変更すると(そしてASCII文字のみをプッシュします)、正常に動作します。ただし、 wchar_t* 文字列を適切にシリアル化および逆シリアル化する方法がわかりません。