如何从C#运行交互式RPG应用程序?

时间:2018-06-19 15:51:50

标签: c# process desktop-application rpg

我正在尝试从C#运行交互式RPG / MAPICS程序。为此,我正在尝试通过PCSWS.EXE启动.ws文件,并从C#向其写入输入。

仿真器可以正常启动,但是我似乎无法通过标准输入或SendMessage(我通过SETTEXT和KEYDOWN尝试过)向其发送输入。

我在做什么错,在这里?我应该如何从C#启动交互式RPG程序?

public void LaunchRPGApp(Application program)
{
    var processInfo = new ProcessStartInfo("pcsws.exe")
    {
        WindowStyle = ProcessWindowStyle.Normal,
        Arguments = "\"C:\\Program Files (x86)\\IBM\\Client Access\\Emulator\\Private\\veflast1.ws\"",
        RedirectStandardInput = true,
        UseShellExecute = false,
    };
    var process = Process.Start(processInfo);

    SendTextToProcess(process, "f");//Try via SendMessage

    using (var sr = process.StandardInput)//Try via StdIn
    {
        sr.Write("f");//does nothing
        sr.Close();
    }
}

[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
private void SendTextToProcess(Process p, string text)
{
    const int WM_SETTEXT = 0x000C;
    const int WM_KEYDOWN = 0x0100;
    const int F_KEY = 0x46;
    Thread.Sleep(500);
    var child = FindWindowEx(p.MainWindowHandle, new IntPtr(0), "Edit", null);
    SendMessage(child, WM_KEYDOWN, F_KEY, null);//does nothing
    SendMessage(child, WM_SETTEXT, 0, text);//does nothing
}

2 个答案:

答案 0 :(得分:1)

这是可以尝试的方法,我不是C#程序员,但是我发现了这个here

PCSWS.EXE

有关{{1}} here

的命令行参数的文档

答案 1 :(得分:1)

找到了解决方案-通过在参数后面附加“ / M = {macroName}”,可以在启动PCSWS.EXE时运行VBScript宏。请注意,该宏必须存在于特定的文件夹中。 然后,宏使用autECLSession.autECLPS.SendKeys发送击键。

像这样:

public void LaunchRPGApp(Application program)
{
    MakeMacro(program);

    const string wsPathAndFilename =
        "C:\\Program Files (x86)\\IBM\\Client Access\\Emulator\\Private\\flast1.ws";
    var processInfo = new ProcessStartInfo("pcsws.exe")
    {
        Arguments = "{wsPathandFilename} /M=name.mac"
    };
    Process.Start(processInfo);
}

private void MakeMacro(Application program)
{
    var macroText = GetMacroText(program);//Method to get the content of the macro

    var fileName =
        $"C:\\Users\\{Environment.UserName}\\AppData\\Roaming\\IBM\\Client Access\\Emulator\\private\\name.mac";

    using (var writer = new StreamWriter(fileName))
    {
        writer.Write(macroText);
    }
}