|
本帖最后由 luoxuan 于 2020-3-22 17:54 编辑
我是新手不知道怎么转换,vs设置的是unicode的
#pragma pack (push, 1)
struct send_sys_info {
BYTE mProcType;
short int mProc;
int total;
int type;
int _loc4_;
BYTE pos;
BYTE time;
int color;
short int len;
wchar_t content[1024];
};
#pragma pack(pop)
string WStringToUTF8(const wchar_t* lpwcszWString)
{
char* pElementText;
int iTextLen = ::WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)lpwcszWString, -1, NULL, 0, NULL, NULL);
pElementText = new char[iTextLen + 1];
memset((void*)pElementText, 0, (iTextLen + 1) * sizeof(char));
::WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)lpwcszWString, -1, pElementText, iTextLen, NULL, NULL);
string strReturn(pElementText);
delete[] pElementText;
return strReturn;
}
wstring str = L"欢";
string s = WStringToUTF8(str.c_str());
char sys_data[2048] = {0};
send_sys_info* sys_info = (send_sys_info*) sys_data;
sys_info->mProcType = 3;
sys_info->mProc = 0x0F;
sys_info->total = s.length() + 16;
sys_info->type = 1;
sys_info->_loc4_ = 152961;
sys_info->pos = 0;
sys_info->time = 1;
sys_info->color = 0;
sys_info->len = s.length();
sys_info->content = 这个content该怎么定义,我socket要发送utf8的中文,占用3个字节的,求帮助
int packsize = sys_info->total + 7;
SendData(pSoContext, sys_data, packsize);
还有我socket要发送结构体是不是这么整啊
发送的数据包 03 0F 00 13 00 00 00 01 00 00 00 81 55 02 00 00 01 00 00 00 00 03 00 00 00 00
最后3个00应该是wstring str = L"欢"; 这个欢字怎么发送,问题就在这里
调用完 WStringToUTF8 之后,将返回来的 utf8 的字符串赋值到 content 中,但是要保证 content 的空间够用哈。之后直接发送 sys_info 这个结构体就可以了
|
上一篇: t_main是unicode编码的主函数是什么意思?下一篇: 无法对win10系统的计算器的窗口进行像课程中的操作,现在是2020年了,用win7的人少
|