我在 C++ 中使用本机主机,当我将 base64 从本机应用程序发送到大小为 base64 < 1M 的 chrome 扩展(本机消息传递)时,程序仍在运行。但是当我将base64从本机应用程序发送到大小base64> 1M的chrome扩展(本机消息传递)时,程序出现错误“与本机消息传递主机通信时出错”我的代码如下
int _tmain(int argc, _TCHAR* argv[])
{
std::cout.setf( std::ios_base::unitbuf );
unsigned int c, t=0;
inp="";
t=0;
// Sum the first 4 chars from stdin (the length of the message passed).
for (int i = 0; i <= 3; i++) {
//t += getchar();
t += std::pow(256.0f, i) * getchar();
}
// Loop getchar to pull in the message until we reach the total
// length provided.
for (int i=0; i < t; i++) {
c = getchar();
inp += c;
}
unsigned int len = inp.length();
// We need to send the 4 btyes of length information
std::cout << char(((len>>0) & 0xFF))
<< char(((len>>8) & 0xFF))
<< char(((len>>16) & 0xFF))
<< char(((len>>24) & 0xFF));
// Now we can output our message
std::cout << inp;
return 0;
}