2

as400 エミュレーター (IBM のパーソナル コミュニケーション iSeries) でプロセスを自動化しようとしています。そのために、EHLLAPI を使用してエミュレーターに接続するコード ( CodeProjectから完全に盗みませんでした) を使用しています。

テスト用のいくつかのボタンといくつかのテキストボックスを備えたコードを実装するための Winforms を作成しました。EHLLAPI からメソッドを公開するクラスは次のとおりです。

public class EhllapiFunc //Class used to import the DLL.
{
    [DllImport("PCSHLL32.dll")]
    public static extern UInt32 hllapi(out UInt32 Func, StringBuilder Data, out UInt32 Length, out UInt32 RetC);
}

class EhllapiWrapper
{
    /*These are the constants used to as function codes that are sent as parameters to the function in the DLL. 
    There are a lot more constants but these are the only ones used for the moment*/
    const UInt32 HA_CONNECT_PS = 1; /* 000 Connect PS*/
    const UInt32 HA_DISCONNECT_PS = 2; /* 000 Disconnect PS*/
    const UInt32 HA_COPY_PS_TO_STR = 8; /* 000 Copy PS to String*/
    
    /*EHLLAPI return codes. There are a lot more. I'll leave just some of them as I'm not getting any return codes in my issue*/
    const UInt32
        HARC_SUCCESS = 0; /* 000 Good return code.*/
    const UInt32
        HARC99_INVALID_INP = 0; /* 000 Incorrect input*/
    const UInt32
        HARC_INVALID_PS = 1; /* 000 Invalid PS, Not*/
    const UInt32
        HARC_BAD_PARM = 2; /* 000 Bad parameter, or*/
    
    //Method to connect to the emulator.
    public static UInt32 Connect(string sessionID)
    {
        StringBuilder Data = new StringBuilder(4);
        Data.Append(sessionID);
        UInt32 rc = 0;
        UInt32 f = HA_CONNECT_PS;
        UInt32 l = 4;
        return EhllapiFunc.hllapi(out f, Data, out l, out rc);
    }

    //Method to disconnect.
    public static UInt32 Disconnect(string sessionID)
    {
        StringBuilder Data = new StringBuilder(4);
        Data.Append(sessionID);
        UInt32 rc = 0;
        UInt32 f = HA_DISCONNECT_PS;
        UInt32 l = 4;
        return EhllapiFunc.hllapi(out f, Data, out l, out rc);
    }

    /*This is the method where I'm having the problem.*/
    public static UInt32 ReadScreen(int position, int len, out string txt)
    {
        StringBuilder Data = new StringBuilder(3000);
        UInt32 rc = (UInt32)position;
        UInt32 f = HA_COPY_PS_TO_STR;
        UInt32 l = (UInt32)len;
        UInt32 r = EhllapiFunc.hllapi(out f, Data, out l, out rc);
        txt = Data.ToString();
        return r;
    }
}

これは、フォームでメソッドを呼び出すために使用する OnClick イベントです。

private void bReadString_Click(object sender, EventArgs e)
{
    //I tried cleaning the TextBox where the outputed string is sent before calling the method.
    tbReadOut.Text = "";
    string s;
    //I send the position and string length entered on the form to the method and then "s" is modified inside the method "ReadScreen".
    EhllapiWrapper.ReadScreen(Convert.ToInt32(tbReadPos.Text), Convert.ToInt32(tbReadLen.Text), out s);
    tbReadOut.Text = s;
}

問題の例を次に示します。カーソル位置「30」から2文字のサイズの文字列を取得する必要があります。

私が得るゴミは「文字列結果」にあります 私が乗るゴミ

これは、私が取得するはずだったエミュレーターのリージョンで、「Sy」だけです。 ここに画像の説明を入力

これはうまくいくこともあれば、うまくいかないこともあります。エミュレータのさまざまな部分を試してみましたが、問題は同じです。カーソル位置の取得と文字列の送信は正常に機能します。エミュレータから文字列を取得しようとしているときです。

このコードはもともと 2005 年に投稿されたものであるため、どこで答えを探すべきかさえわかりません。

4

1 に答える 1