【发布时间】:2021-12-03 02:50:30
【问题描述】:
我正在尝试在 as400 模拟器(IBM 的 Personal Communications iSeries)中自动化一个进程,为此,我使用了一些代码(我完全没有从 CodeProject 窃取),它使用 EHLLAPI连接到模拟器。
我创建了一个 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 个字符的字符串:
这有时有效,有时无效。我尝试了模拟器的不同部分,问题是一样的。获取光标位置并发送字符串工作正常,只是当我试图从模拟器中获取字符串时。
我什至不知道在哪里寻找答案,因为这段代码最初是在 2005 年发布的。
【问题讨论】:
-
this.tbReadLen.Text 是什么?
-
@Duston TextBox 中的文本,我在其中获取了我要读取的字符串的长度。在屏幕截图中显示为“长度”和一个蓝色文本框。
-
我只是在代码中添加了一些 cmets 以使其更清晰,并删除了两个
this,因为它们是不必要的。
标签: c# winforms ibm-midrange hllapi