Tobe Tung
Tobe Tung

Reputation: 11

How to implement ehllapi in C#

I'm working with IBM i Access Client Solution and have to implement some functions of ehllapi.dll to interact with the grean screen.

It has IBM document in this link and some useful sample code in this link. The sample code implemented some simple functions and it worked perfectly, but I can't find the way how to implement the function which have to pass the data string contained the specific data for each byte to the interface method which been implemented in the sample source code. (like Window Status function)

Can anyone help me? how can I create my data string to pass to the C# code interface below?

public class EhllapiFunc
{
    [DllImport("PCSHLL32.dll")]
    public static extern UInt32 hllapi(out UInt32 Func, StringBuilder Data, out UInt32 Length, out UInt32 RetC);
}

Thanks for your help.

---------------EDIT1-----------------------

I tried to create Data Buffer parameter using byte[] like this

byte[] buffer = new byte[28];
buffer[0] = (byte)65     // letter A
buffer[4] = (byte)0x01   // the fifth byte (X'01' for set status)
... 

and then pass into the edited prototype

public class EhllapiFunc
{
    [DllImport("PCSHLL32.dll")]
    public static extern UInt32 hllapi(out UInt32 Func, out byte[] Data, out UInt32 Length, out UInt32 RetC);
}

but it not working! Anything wrong with my code?

---------------Solution-----------------------

I did like @battlmonstr said and it worked!

Protype will be public class EhllapiFunc

{
    [DllImport("PCSHLL32.dll")]
    public static extern UInt32 hllapi(out UInt32 Func, Byte[] Data, out UInt32 Length, out UInt32 RetC);
}

And the implement will be

Byte[] buffer = new Byte[28];   // Byte[]   not byte[]
MemoryStream ms = new MemoryStream(buffer);
BinaryWriter bw = new BinaryWriter(ms); 

bw.Write((Byte)65);             // letter A 
bw.Seek(4, SeekOrigin.Begin);   // jump to 5th byte
bw.Write((Byte)0X01)            // hexa 01

Upvotes: 0

Views: 1522

Answers (1)

battlmonstr
battlmonstr

Reputation: 6280

It seems that it is possible to build this Data Buffer parameter using MemoryStream + BinaryWriter, take out byte[] and pass it into hllapi. For that you need to change a prototype to take byte[] instead of StringBuilder, because in the case of Window Status function it is not an ASCII string. Depending on what you want the composition of bytes is different there, as documented in your last link.

Upvotes: 0

Related Questions