using Delphi DLL in C#
Posted on 2003-11-16
I want to use a delphi DLL in my C# program, but am having a problem.
Delphi function prototype (LongInt has size od 4 bytes in Delphi):
FUNCTION _Status_Cmd( PortIndex : LongInt;
DevAddr : LongInt;
VAR Data : ARRAY OF LongInt): LongInt; STDCALL;
Then, in my C program, I have:
[DllImport("comcom32.dll", ExactSpelling=false, SetLastError=true)]
private static extern int _Status_Cmd(int PortIndex, int DevAddr, int Data);
int iData = new int; (in delphi example, iData is set to 100 zero elements, too)
int PortIndex = 1, ret;
ret = _Status_Cmd(PortIndex, 0, iData);
After return, data should be like this:
5 0 32 132 142 0 0 0 0 .......
as is the case, if I use this function in Delphi, but if I use the function in my C# program, I get this:
5 0 0 0 0 0 0 0 0 ........ (all zeroes, except first element in int array)
So, only the first element is set correctly, others are left alone. I tried with various marshalling functions, but with no success so far.
All suggestions appreciated.