c#从远程PLC读取使用cc链接IE控件 [英] c#read from remote PLC use cc link IE control

查看:484
本文介绍了c#从远程PLC读取使用cc链接IE控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用这个应用程序。链接库只适用于VC ++,所以我将它包装到一个可以在c#中使用的库中,然后在c#中导入,我在VC ++中测试了它的功能它运行正常。但在C#中,虽然返回值为0,但是什么都不读,结果为空。希望有人能帮助我。提前谢谢。



这里是原始库头文件中的函数。



LONG WINAPI mdReceiveEx( LONG,LONG,LONG,LONG,LPLONG,LPVOID);



我用C ++包裹



MELFUNC_API long MmdReceiveEx(long path,long netno,long stno,long devtyp,long devno,long size,short * data); long MmdReceiveEx(long path,long netno,long stno,long devtyp,long devno,long size,short * data)// {

long result = mdReceiveEx(path,netno,stno,devtyp,devno ,&size,data);

返回结果; }



并导入c#



[DllImport(@dllname,CallingConvention = CallingConvention.Cdecl)]



static extern int MmdReceiveEx(int path,int netno,int stno,int devtyp,int devno,int size,out short [] data);



和函数叫



int retval2 = MmdReceiveEx(151,1,2,23,0x00,sizetst, ref buf1);



retval2将为0,执行后buf1为null。任何人都可以帮助我吗?

This is the first time for me in this application. link library is only for VC++, so I wrapped it into a library that can use in c#, and then import in c#, I 've tested the function in VC++ it works fine.but in C#, although the return value is 0, I can read nothing, the result is null. hope somebody can help me. thanks in advance.

here is the function in original library header file.

LONG WINAPI mdReceiveEx( LONG, LONG, LONG, LONG, LONG, LPLONG, LPVOID );

and I wrapped in C++

MELFUNC_API long MmdReceiveEx(long path,long netno,long stno,long devtyp,long devno,long size,short *data); long MmdReceiveEx(long path,long netno,long stno,long devtyp,long devno,long size,short *data)// {
long result=mdReceiveEx(path,netno,stno,devtyp,devno,&size,data);
return result; }

and import in c#

[DllImport(@dllname, CallingConvention = CallingConvention.Cdecl)]

static extern int MmdReceiveEx(int path, int netno, int stno, int devtyp, int devno, int size, out short[] data);

and the function be called

int retval2 = MmdReceiveEx(151, 1, 2, 23, 0x00, sizetst, ref buf1);

the retval2 will be 0 and buf1 be null after executed. can anybody help me?

推荐答案

这是进行p / invoke声明的最简单方法:https://visualstudiogallery.msdn.microsoft.com/9CA9D544-05D2-487B-AB49-31851483C1CC [ ^ ]
This is the easiest way to make p/invoke declaration: https://visualstudiogallery.msdn.microsoft.com/9CA9D544-05D2-487B-AB49-31851483C1CC[^]


这篇关于c#从远程PLC读取使用cc链接IE控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆