Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi 5-6 DLL function in C#

Status
Not open for further replies.

DelphiN00b

Programmer
Jul 13, 2011
1
I'm having troubles working a return array from a Delphi5-6 Dll within C#
My.dll communicates between the PC and a PIC and works in the Delphi created test.exe

Delphi
Code:
function GetArray1(MemAdr, MemLen: integer): TData; stdcall; external 'My.dll';
returns the TData as a byte array.

C#
Code:
[DllImport("My.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern byte[] GetArray1(int MemAdr, int MemLen);

As My.dll does the PC to PIC exchange, am I correct in assuming the MemAdr and MemLen only need to be passed as integers?

Only the returned array TData or Byte[] needs to be Marshalled, correct?

How would I Marshal the returning Array?
 
You might want to rewrite the function signature on the Delphi side. A c/c++ exportable function is compatible to .NET interops. So try using a convention that is similar to how you would do it in MS c/c++.

Normally, when returning array, the exportable function (Delphi) takes in a pointer to the array data, and a ref param referring to the number of elements the array contains.

Not an expert on c++, just sharing my 2c.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top