Sunny Wang

Sunny Wang

  • NA
  • 4
  • 2.1k

c#read from remote PLC use cc link IE control

Jan 9 2015 6:28 AM
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, short size, ref 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?