Native Host メッセージングを使用した Chrome 拡張機能に取り組んでいます。ホスト アプリケーションでメッセージ テキストを使用できません。接続の確立から拡張での応答の取得まで、すべて正常に機能しています。単純なテキスト データ型 (文字列/文字) でさらに使用/実行するには、アプリケーションでメッセージ テキストを使用する必要があります。メッセージが UTF8 でエンコードされた形式であることはわかっていますが、デコードしようとしましたが、まだ問題が発生しています。
メッセージ chrome 拡張コンソールをデコードすると、エラーが表示されます:「ネイティブ メッセージング ホストとの通信中にエラーが発生しました。」「cout」の後にそのメッセージテキストを使用すると、「ネイティブメッセージングホストとの通信中にエラーが発生しました」という同じエラーが発生します。メッセージの直接送受信は問題なく動作します。
コードは次のようなものです:
std::string mycode(std::string data){
data= data+"abc"; //changing text to any thing.
cout<< data;
anotherFunction(data);//killing processes using string data
}
int main(int argc, char* argv[])
{
std::cout.setf( std::ios_base::unitbuf );
while (true)
{
unsigned int ch, inMsgLen = 0, outMsgLen = 0;
std::string input = "", response = "";
std::cin.read((char*)&inMsgLen, 4);
if (inMsgLen == 0)
{
break;
}
else
{
for (int i=0; i < inMsgLen; i++)
{
ch = getchar();
input += ch;
}
}
response.append("{\"echo\":").append(input).append("}");
outMsgLen = response.length();
std::cout.write((char*)&outMsgLen, 4);
std::cout << response;
cout<< input;
//using "input" variable for further user
mycode(input);
}
return 0;
}