【扩展】
接下来,为了解决中文乱码的问题,定义下列两个方法:
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"老人"); // 事件名
效果: