简体   繁体   English

如何在C#中实现ehllapi

[英]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. 我正在使用IBM i Access Client解决方案,并且必须实现ehllapi.dll的某些功能才能与grean屏幕进行交互。

It has IBM document in this link and some useful sample code in this link . 它在IBM文档此链接和一些有用的示例代码在这个环节 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? 如何创建数据字符串以传递到下面的C#代码接口?

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----------------------- --------------- EDIT1 -----------------------

I tried to create Data Buffer parameter using byte[] like this 我试图像这样使用byte[]创建数据缓冲区参数

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! 我确实喜欢@battlmonstr说的,它起作用了!

Protype will be public class EhllapiFunc Protype将是公共类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

It seems that it is possible to build this Data Buffer parameter using MemoryStream + BinaryWriter, take out byte[] and pass it into hllapi. 似乎可以使用MemoryStream + BinaryWriter构建此数据缓冲区参数,取出byte[]并将其传递给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. 为此,您需要更改原型以采用byte[]而不是StringBuilder,因为在“窗口状态”功能的情况下,它不是ASCII字符串。 Depending on what you want the composition of bytes is different there, as documented in your last link. 如您所希望的那样,字节的组成在此有所不同,如上一个链接中所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM