Using EHLLAPI in C# - CodeProject
Using EHLLAPI in C# - CodeProject
Using EHLLAPI in C#
Luca Bertoncini Rate me: 4.68/5 (16 votes)
17 Feb 2005 CPOL
This article will explain how to interact with AS/400 applications using the PCSHLL32.DLL library distributed with IBM Client Access
emulator.
This article will explain how to interact with AS/400 applications using the library distributed with IBM Client Access emulator:
PCSHLL32.DLL. If you use a different emulation software, you can apply the concepts exposed in this article with some minor
modifications.
https://www.codeproject.com/Articles/9615/Using-EHLLAPI-in-C 1/6
4/24/2021 Using EHLLAPI in C# - CodeProject
EHLLAPI Concept
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.
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.
HA_CONNECT_PS: 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: 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.
To import the DLL function, I used this code:
Copy Code
This class contains just a static function referrer to the PCSHLL32 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.
Data.Append(sessionID);
UInt32 rc=0;
UInt32 f=HA_CONNECT_PS; //function code
https://www.codeproject.com/Articles/9615/Using-EHLLAPI-in-C 2/6
4/24/2021 Using EHLLAPI in C# - CodeProject
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
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
1. Connect to session.
2. Set cursor position.
3. Send string.
4. Read screen.
5. Disconnect.
Some Notes
Session ID for Client Access emulator is a char 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, 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.
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Share
https://www.codeproject.com/Articles/9615/Using-EHLLAPI-in-C 4/6
4/24/2021 Using EHLLAPI in C# - CodeProject
Search Comments
connection
Membro 14718217 16-Jan-20 9:22
https://www.codeproject.com/Articles/9615/Using-EHLLAPI-in-C 5/6
4/24/2021 Using EHLLAPI in C# - CodeProject
Re: Error ( an attempt to load a program with an incorrect format was made.)
Member 10020480 19-Aug-16 11:26
Re: Error ( an attempt to load a program with an incorrect format was made.)
everton.rpa 19-Aug-16 12:15
[EHLLAPI.EhllapiWrapper]::SendStr("@E") returning 5 rc
Kingkongclicker 21-Jun-16 1:02
Refresh 1 2 3 Next ᐅ
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
https://www.codeproject.com/Articles/9615/Using-EHLLAPI-in-C 6/6