在WinAPI函数中使用std :: wstring:并非所有文本都已发送

时间:2016-07-26 05:12:38

标签: c++ winapi

HTTP发布数据时;如果我使用header { margin-top:0px; background-color:rgba(255,255,255,0.7); height:140px; } 作为参数,则不会发布所有文本。但是,如果我使用标准的TCHAR数组,则会发布所有文本。为什么会发生这种情况?如何继续使用std::wstring

std::wstring

1 个答案:

答案 0 :(得分:1)

HttpSendRequest文档说:

  

dwOptionalLength [in]
  可选数据的大小,以字节为单位。如果没有可选的数据要发送,则此参数可以为零。

size()返回字符串中的字符元素数,而不是字节数的字符串大小。 Windows上wchar_t的字节大小为2,因此不是:

HttpSendRequest(hRequest, hdrs, -1, (LPVOID)fData.c_str(), fData.size()); 

需要这样:

HttpSendRequest(hRequest, hdrs, -1, (LPVOID)fData.c_str(), fData.size() * sizeof(wchar_t));