名前付きパイプを使用しているC++プロジェクトにc#プロジェクトを接続しようとしていますが、C++プロジェクトが接続しません。C#名前付きパイプ接続
PS:私はの使用理解していない私のパイプ名の前に「\\を\パイプ\。」:.exeファイルの両方が同じファイルに
側の質問です。それは何をし、本当に必要なのですか?
Program.csの
static class Program
{
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
pipeHandler pipe = new pipeHandler();
var proc = new Process();
proc.StartInfo.FileName = "cplpltestpipes.exe";
proc.Start();
pipe.establishConnection();
Application.Run(new Form1(pipe));
}
}
public class pipeHandler
{
private StreamReader re;
private StreamWriter wr;
private NamedPipeServerStream pipeServer;
public void establishConnection()
{
pipeServer = new NamedPipeServerStream("myNamedPipe1");
pipeServer.WaitForConnection();
re = new StreamReader(pipeServer);
wr = new StreamWriter(pipeServer);
}
public void writePipe(string text)
{
wr.Write(text);
}
public string readPipe()
{
if(re.Peek()==-1)
System.Threading.Thread.Sleep(2000);
if (re.Peek() > -1)
{
string s;
s = re.ReadToEnd();
return s;
}
else
return "fail";
}
}
のForm1.cs:
public partial class Form1 : Form
{
pipeHandler pipePointer;
public Form1(pipeHandler pipe)
{
pipePointer=pipe;
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
pipePointer.writePipe(textBox1.Text);
textBox2.Text = pipePointer.readPipe();
}
}
C++クライアント
ここに私のコードは、多分あなたは
C#のサーバーのエラーを見つけることができます プログラムを実行する
}
だけのC#
でこの例外を与える**************例外テキスト************ ** System.InvalidOperationException:パイプがまだ接続されていません。 .... .... ....
およびC++では、ちょうどあなたがCreateFileのは、オブジェクトが文字列によって表されることを知っているんかCreateFile
を呼び出すと、コンソール
を削除し、私は '表示されていない" \\。\パイプどこでもあなたのコードでは、 '\。 –
私はそれが何を今ないので、それはありませんし、いずれにしても動作しません。 – Awesome
パイプ名の説明については、https://msdn.microsoft.com/en-us/library/windows/desktop/aa365783(v=vs.85).aspxを参照してください。 –