【擴展】
接下來,為了解決中文亂碼的問題,定義下列兩個方法:
int RubyMarshal::AddMember(char *memname, wchar_t *memvalue)
{
int count = BeginMember(memname);
count += WriteString(memvalue);
return count;
}
int RubyMarshal::WriteString(wchar_t *pStr)
{
int size = WideCharToMultiByte(CP_UTF8, NULL, pStr, -1, NULL, 0, NULL, NULL);
char *buffer = new char[size];
WideCharToMultiByte(CP_UTF8, NULL, pStr, -1, buffer, size, NULL, NULL);
filestream->put(RBT_STRING);
int count = WriteLong(size - 1) + size;
filestream->write(buffer, size - 1);
delete[] buffer;
return count;
}
然後在執行時給成員變量的值加上L就行了。
例如:
rms.AddMember("name", L"老人"); // 事件名
效果: