How to call in C# function from Win32 DLL with custom objects

Posted by marko on Stack Overflow See other posts from Stack Overflow or by marko
Published on 2010-05-28T12:28:36Z Indexed on 2010/05/28 12:32 UTC
Read the original article Hit count: 206

Filed under:
|
|
|
|

How to use in C# function from Win32 DLL file made in Delphi. When function parameters are custom delphi objects?

Function definition in Delphi:

function GetAttrbControls(    Code     : PChar;
                              InputList: TItemList;
                              var Values   : TValArray): Boolean; stdcall; export;

Types that use:

type
  TItem = packed record
    Code : PChar;
    ItemValue: Variant;
  end;

TItemList = array of TItem;

TValArray = array of PChar;

Example in C# (doesn't work):

[StructLayout(LayoutKind.Sequential)]
 public class Input
 {
     public string Code;
     public object ItemValue;
 };


[DllImport("Filename.dll", EntryPoint = "GetValues", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
    public static extern bool GetValues(string Code, Input[] InputList, ref StringBuilder[] Values);

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET