Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4615614
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:51:55+00:00 2026-05-22T01:51:55+00:00

I have this function defined in a delphi code: procedure TestFLASHWNew( name: array of

  • 0

I have this function defined in a delphi code:

procedure TestFLASHWNew(
    name: array of string; 
    ID: array of Integer;
    var d1:double
); stdcall;

How can I define and call it from C#?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:51:56+00:00Added an answer on May 22, 2026 at 1:51 am

    This is a bit of a messy P/Invoke because you can’t (to the best of my admittedly limited knowledge) use any of the built-in easy marshalling techniques. Instead you need to use Marshal.StructureToPtr like this:

    C#

    [StructLayout(LayoutKind.Sequential)]
    public struct MyItem
    {
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Name;
        public int ID;
    }
    
    [DllImport(@"mydll.dll")]
    private static extern void TestFLASHWNewWrapper(IntPtr Items, int Count, ref double d1);
    
    static void Main(string[] args)
    {
        MyItem[] items = new MyItem[3];
        items[0].Name = "JFK";
        items[0].ID = 35;
        items[1].Name = "LBJ";
        items[1].ID = 36;
        items[2].Name = "Tricky Dicky";
        items[2].ID = 37;
    
        IntPtr itemsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MyItem))*items.Length);
        try
        {
            Int32 addr = itemsPtr.ToInt32();
            for (int i=0; i<items.Length; i++)
            {
                Marshal.StructureToPtr(items[i], new IntPtr(addr), false);
                addr += Marshal.SizeOf(typeof(MyItem));
            }
    
            double d1 = 666.0;
            TestFLASHWNewWrapper(itemsPtr, items.Length, ref d1);
            Console.WriteLine(d1);
        }
        finally
        {
            Marshal.FreeHGlobal(itemsPtr);
        }
    }
    

    Delphi

    TItem = record
      Name: PChar;
      ID: Integer;
    end;
    PItem = ^TItem;
    
    procedure TestFLASHWNewWrapper(Items: PItem; Count: Integer; var d1: Double); stdcall;
    var
      i: Integer;
      name: array of string;
      ID: array of Integer;
    begin
      SetLength(name, Count);
      SetLength(ID, Count);
      for i := 0 to Count-1 do begin
        name[i] := Items.Name;
        ID[i] := Items.ID
        inc(Items);
      end;
      TestFLASHWNew(name, ID, d1);
    end;
    

    I’ve implemented it with a wrapper function that calls your TestFLASHWNew function but you’ll no doubt want to re-work it.

    I’ve assumed you are using a Delphi with Unicode strings. If not then change [MarshalAs(UnmanagedType.LPWStr)] to [MarshalAs(UnmanagedType.LPStr)].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Delphi DLL with a function defined as: function SubmitJobStringList(joblist: tStringList; var
I have this user defined function. public partial class UserDefinedFunctions { static int i;
I have an inline member function defined under class MyClass int MyClass::myInlineFunction(); This function
I have a function defined like this: public static void ShowAbout(Point location, bool stripSystemAssemblies
I have this function in my Javascript Code that updates html fields with their
I have this function in my head: <head> window.onload = function(){ var x =
I have this function... private string dateConvert(string datDate) { System.Globalization.CultureInfo cultEnGb = new System.Globalization.CultureInfo(en-GB);
I have a static library. This library have the following function defined int WriteData(LPTSTR
I have this function function get_last(){ $.ajax({ url:'fronta.php?get_last&last=1', success:function(data) { var last = parseInt(data);
I have a string in my function defined like .. char *key=anyvalue; Now I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.