简体   繁体   English

从控制台窗口(C ++应用程序)重定向到文本框(C#app)

[英]Redirect from console window(C++ app) to textbox(C# app)

I'm creatin application(C#) that need run another app. 我是需要运行另一个应用程序的creatin应用程序(C#)。 This. 这个。 app is game(C++,Directx7,GDI, I don't have source) that show console window for debugging from dll(static). 应用程序是游戏(C ++,Directx7,GDI,我没有源代码),显示从dll(静态)调试的控制台窗口。 For show console window this dll has this lines: 对于show console window,这个dll有以下几行:

AllocConsole();
freopen("CONIN$","rb",stdin);   
freopen("CONOUT$","wb",stdout);
freopen("CONOUT$","wb",stderr);

In my c# app. 在我的c#app中。 i want hide console window and redirect text from console window to textbox. 我想隐藏控制台窗口并将文本从控制台窗口重定向到文本框。 For hide console window i'm using winapi FindWindow , ShowWindow is not problem. 对于隐藏控制台窗口我正在使用winapi FindWindowShowWindow没有问题。 But how i can redirect text(output) from console window to textbox? 但是我如何将文本(输出)从控制台窗口重定向到文本框?

You can run your game using following code: 您可以使用以下代码运行游戏:

     Process process = new Process();
     process.StartInfo.FileName = "\"" + pathToGame + "\"";
     //process.StartInfo.Arguments = args;
     process.StartInfo.RedirectStandardOutput = true;
     process.StartInfo.RedirectStandardError = true;
     process.StartInfo.UseShellExecute = false;
     process.OutputDataReceived += new DataReceivedEventHandler(ReadOutput);
     process.ErrorDataReceived += new DataReceivedEventHandler(ReadOutput);

     process.Start();
     process.BeginOutputReadLine();
     process.BeginErrorReadLine();

     //process.WaitForExit();

CL output and errors will go here CL输出和错误将在这里

  private static void ReadOutput(object sender, DataReceivedEventArgs e)
  {
     if (e.Data != null)
     {
        //your output here
     }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用C++ dll的方法在C# app打开console window,如何抑制console? - Call of a method from C++ dll opens console window in C# app, how do I suppress the console? 在C#控制台应用程序中运行C ++控制台应用程序 - Running a c++ console app inside a C# console app C++ opencv 应用程序在 C# window - C++ opencv app in C# window 将cout从C ++ dll重定向到C#中的文本框 - Redirect cout from C++ dll to a textbox in C# C#停止等待文本框中的用户输入NOT CONSOLE APP - C# Stop Wait for user input in textbox NOT CONSOLE APP C# 在新的控制台窗口中从另一个应用程序运行控制台应用程序 - C# Run console application from another app in a new console window 使用C#控制台应用程序互操作C ++(DLL)时出现问题 - Problems Interoping C++ (DLL) with C# console app 尝试将 C++ 控制台应用程序转换为 C# 类库 - Trying to convert a C++ console app into a C# class library 将DllImport从C#控制台应用程序中的静态类的静态成员转换为C ++ CLR控制台应用程序的成员 - Translate DllImport from static member of static class in C# console app to member of C++ CLR console app 任务计划程序启动时隐藏C#控制台应用程序窗口 - Hide C# Console App Window When Started by Task Scheduler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM