先日こちらでC#のネイティブアプリからchrome を操作する方法として、
naitive messagingというものがあると教えていただき、いろいろ試しております。
https://teratail.com/questions/98869
chrome→登録したexe起動、メッセージ送信はできましたが、
exeをWINフォームアプリにした場合、フォームが立ち上がりません。
※タスクマネージャー上は立ち上がっていました。
先日教えていただいたのは、
拡張機能<-->通信用EXE<-->操作用のGUIのEXE
という2段階のもので、今回は上記の通信用EXEを操作用EXEに
組み込めないかということで試行錯誤しております。
恐らく何か意味があって2段階に分かれているのだと思いますが、
chromeから呼び出すとバックグラウンドでしか起動しないなど
何か制限があるのでしょうか。
EXE側は以下のコードとなっておりこれをフォームのコンストラクタから
呼び出して試しております。
C#
1using System; 2using System.IO; 3 4namespace Chrome 5{ 6 class NativeMsg 7 { 8 public static string OpenStandardStreamIn() 9 { 10 Stream stdin = Console.OpenStandardInput(); 11 int length = 0; 12 byte[] bytes = new byte[4]; 13 stdin.Read(bytes, 0, 4); 14 length = BitConverter.ToInt32(bytes, 0); 15 string input = ""; 16 for (int i = 0; i < length; i++) input += (char)stdin.ReadByte(); 17 return input; 18 } 19 public static void OpenStandardStreamOut(string stringData) 20 { 21 string outString = "\"" + stringData + "\""; 22 int dataLength = outString.Length; 23 byte[] bytes = BitConverter.GetBytes(dataLength); 24 Stream stdout = Console.OpenStandardOutput(); 25 for (int i = 0; i < 4; i++) stdout.WriteByte(bytes[i]); 26 Console.Write(outString); 27 } 28 29 } 30}
恐れ入りますがご教授宜しくお願い申し上げます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/12 11:44