在C#中使用EHLLAPI(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/emulation/using-ehllapi-in-c-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 6 分钟阅读 - 2691 个词 阅读量 0在C#中使用EHLLAPI(译文)
原文地址:https://www.codeproject.com/Articles/9615/Using-EHLLAPI-in-C
原文作者:Luca Bertoncini
译文由本站 robot-v1.0 翻译
前言
This article will explain how to interact with AS/400 applications using the PCSHLL32.DLL library distributed with IBM Client Access emulator.
本文将解释如何使用与IBM Client Access仿真器一起分发的PCSHLL32.DLL库与AS/400应用程序进行交互.
从C#使用EHLLAPI(Using EHLLAPI from C#)
EHLLAPI(扩展的高级语言应用程序编程接口)是用于建立与AS400应用程序的接口的标准库.它与所有主要的仿真供应商(RUMBA,IBM Client Access等)一起分发,并且作为DLL自动安装.(EHLLAPI (Extended High Level Language Application Programming Interface) is a standard library to build interfaces to AS400 applications. It’s distributed with all major emulation vendors (RUMBA, IBM Client Access, …), and it’s installed automatically as DLL.)
本文将说明如何使用与IBM Client Access仿真器一起分发的库与AS/400应用程序进行交互:(This article will explain how to interact with AS/400 applications using the library distributed with IBM Client Access emulator:)PCSHLL32.DLL(PCSHLL32.DLL).如果您使用其他仿真软件,则可以应用本文中公开的概念,并进行一些小的修改.(. If you use a different emulation software, you can apply the concepts exposed in this article with some minor modifications.)
EHLLAPI概念(EHLLAPI Concept)
在许多公司中,数据集成并不是那么简单,因为许多程序都非常老,数据库结构也不好.即使可以使用ODBC驱动程序访问数据,真正的问题还是对数据结构和集成的了解:为插入新的产品代码我必须更改哪些表?客户的所有数据都在哪里(在哪些表中)?这些以及许多其他问题都有一个简单的答案:询问用户并学习他们在屏幕上键入的命令以插入或读取信息.您可以解决问题:知道操纵数据的逻辑并不重要,重要的是要知道用户键入的"视频"命令.(In a lot of companies, data integration is not so simple because a lot of programs are very old and databases are not well structured. Even if data can be accessed using ODBC drivers, the real problem is the knowledge of data structures and integration: which tables I must change to insert a new product code? Where are all the data of a customer (in which tables)? These and a lot of other questions have a simple answer: ask to users and learn the commands they type on the screen to insert or read information. You translate the problem: it’s not important to know the logic to manipulate data, what’s important is to know the “video” command the users type.)
用于与AS/400进行交互的接口称为"屏幕抓取":它基于以下事实:仿真器软件使用char接口与AS/400程序进行交互.使用此界面,您可以读取和写入仿真屏幕.如果将其插入高级窗口程序,这种非常简单的机制便可以发挥其全部功能.(The interface used to interact with AS/400 is called “screen scraping”: it’s based on the fact that emulator software use a char interface to interact with AS/400 programs. Using this interface, you can read from and write to emulation screens. This really simple mechanism reveals all its power if inserted in a high level window program.)
DLL导出功能(DLL Exported Function)
*PCSHLL32.DLL(PCSHLL32.DLL)*仅包含一个名为(includes just a function named) HLLAPI
接收一个参数(功能代码):通过更改此参数的值,我们可以执行所有操作. DLL中几乎有一百个可用函数,并声明为(that receives a parameter (function code): by changing the value of this parameter, we can perform all the operations. There are almost one hundred functions available in the DLL and declared as) const
内部代码.根据我的经验,我仅使用了以下五个功能:(inside code. In my experience, I used just five of these functions:)
HA_CONNECT_PS
:连接到客户端会话(每个会话都由ID" A"," B"等标识).(: connect to a client session (every session is identified by an ID: “A”, “B”, and so on).)HA_DISCONNECT_PS
:与客户端会话断开连接.(: disconnect from a client session.)HA_SET_CURSOR
:将光标设置在绝对位置(行* 80(或132)+列).(*: set the cursor in the absolute position (rows * 80 (or 132) + cols).*)HA_SENDKEY
:将字符串发送到客户端会话.(: send a string to a client session.)HA_COPY_PS_TO_STR
:从视频中读取.(: read from video.)HA_WAIT
:等待会话取消阻止.(: wait for session deblocking.) 要导入DLL函数,我使用了以下代码:(To import the DLL function, I used this code:)
public class EhllapiFunc
{
[DllImport("PCSHLL32.dll")]
public static extern UInt32 hllapi(out UInt32 Func,
StringBuilder Data, out UInt32 Length, out UInt32 RetC);
}
此类仅包含一个静态函数引荐来源(This class contains just a static function referrer to the) PCSHLL32
功能.如果一切正常,则此函数返回0,否则返回错误代码(请参阅代码内部).参数在不使用语句的情况下进行声明,因为它们在两个方向(发送和接收值)中使用.取决于(function. This function return 0 if all is OK, otherwise it returns an error code (see inside the code). Parameters are declared without statement because they are used in two directions (to send and receive value). Depending on the) Func
参数,(parameter,) Data
,(,) Length
和(and) RetC
参数具有不同的含义.(parameters have different meanings.)
内部类代码(Inside Class Code)
我创建了一个名为(I created a class named) EhllapiWrapper
.此类提供了五个静态方法.这些方法的结构非常简单:初始化参数,调用(. This class exposes five static methods. The structure of these methods is very simple: initialize parameter, call) HLLAPI
功能暴露(function exposed by the) EhllapiFunc
类,并返回值:(class, and return value:)
public static UInt32 Connect(string sessionID)
{
StringBuilder Data = new StringBuilder(4);
//Data will contain the ID code of Session
Data.Append(sessionID);
UInt32 rc=0;
UInt32 f=HA_CONNECT_PS; //function code
UInt32 l=4; //lenght of data parameter
return EhllapiFunc.hllapi(out f, Data, out l, out rc);
//return error code
}
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);
}
public static UInt32 SetCursorPos(int p)
{
StringBuilder Data = new StringBuilder(0);
//no Data parameter is required
UInt32 rc=(UInt32) p;
//rc parameter contains the curson position
UInt32 f=HA_SET_CURSOR;
UInt32 l=0;
return EhllapiFunc.hllapi(out f, Data, out l, out rc);
}
public static UInt32 GetCursorPos(out int p)
{
StringBuilder Data = new StringBuilder(0);
UInt32 rc=0;
UInt32 f=HA_QUERY_CURSOR_LOC;
UInt32 l=0; //return position
UInt32 r = EhllapiFunc.hllapi(out f, Data, out l, out rc);
p = (int)l;
return r;
}
public static UInt32 SendStr(string cmd)
{
StringBuilder Data = new StringBuilder(cmd.Length);
//Data has the length of cmd string
Data.Append(cmd);
UInt32 rc=0;
UInt32 f=HA_SENDKEY;
UInt32 l=(UInt32)cmd.Length;
//l parameter contain the length of cmd string
return EhllapiFunc.hllapi(out f, Data, out l, out rc);
}
public static UInt32 ReadScreen(int position, int len, out string txt)
{
StringBuilder Data = new StringBuilder(3000);
//Initialization to a MAX char
//(> maximum number of char in a screen session)
UInt32 rc=(UInt32)position;
//set initial position to start reading from
UInt32 f=HA_COPY_PS_TO_STR;
UInt32 l=(UInt32)len;
//set the number of chars that
//function will read from position
UInt32 r = EhllapiFunc.hllapi(out f, Data, out l, out rc);
txt=Data.ToString(); //result
return r;
}
public static UInt32 Wait()
//just wait for execution of a command on session
{
StringBuilder Data = new StringBuilder(0);
UInt32 rc=0;
UInt32 f=HA_WAIT ;
UInt32 l=0;
UInt32 r = EhllapiFunc.hllapi(out f, Data, out l, out rc);
return r;
}
使用Ehllapi包装器类(Using EhllapiWrapper Class)
包装器类的典型用法是:(A typical use of the wrapper class is this one:)
- 连接到会话.(Connect to session.)
- 设置光标位置.(Set cursor position.)
- 发送字符串.(Send string.)
- 阅读屏幕.(Read screen.)
- 断开.(Disconnect.)
一些注意事项(Some Notes)
客户端访问模拟器的会话ID是(Session ID for Client Access emulator is a) char
其中" A"标识打开的第一个会话," B"标识第二个会话,依此类推.您可以使用特定语法向会话发送特殊密钥(请参阅Wrapper类代码中的注释部分).例如,ENTER对应于@ E,F1键对应于@ 1,依此类推.(where “A” identifies the first session opened, “B” the second one, and so on. You can send a special key to the session using a particular syntax (see the comment section inside Wrapper class code). For example, ENTER corresponds to @E, F1 key to @1, and so on.)
示范代码(Demo Code)
演示代码包括一个简单的表单,其中包含五个按钮(每个方法一个).我使用了不同的颜色来标识功能和参数.表格有(Demo code includes a simple form containing five buttons (one for every method). I used a different color to identify functions and parameters. Form has) TopMost
=(=) true
,因此当您与会话互动时,它仍然可见.因此,启动一个客户端访问会话,指定ID(如果是第一个会话,则通常为" A"),然后按Connect.将显示一个带有返回代码的消息框.(, so it remains visible when you interact with session. So start a Client Access session, specify ID (typically “A” if it’s the first session started), and push Connect. A message box is displayed with return code.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# Windows .NET .NET1.1 Visual-Studio VS.NET2003 Dev 新闻 翻译