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

  • Home
  • SEARCH
  • 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 6746757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:21:37+00:00 2026-05-26T12:21:37+00:00

How do I convert the Delphi code into C#? It takes an array of

  • 0

How do I convert the Delphi code into C#? It takes an array of Byte, but I’m not sure what the C# equivalent is. My attempt doesn’t work and throws exceptions like AccessViolationException.

Delphi:

function SetLevel(a: array of byte): boolean; stdcall; external 'DMX510.dll';

C#:

[DllImport("DMX510.DLL")]
public static extern Boolean SetLevel(Byte[] bytearray);

Byte[] byteArray = new Byte[5];
byteArray[1] = 75;
SetLevel(byteArray);
  • 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-26T12:21:38+00:00Added an answer on May 26, 2026 at 12:21 pm

    A Delphi open array is not a valid interop type. You can’t easily match that up with a C# byte[] through a P/invoke. In an ideal world a different interface would be exposed by the native DLL but as you have stated in comments, you do not have control over that interface.

    However, you can trick the C# code into passing something that the Delphi DLL will interpret correctly, but it’s a little dirty. The key is that a Delphi open array declared like that has an extra implicit parameter containing the index of the last element in the array.

    [DllImport(@"DMX510.DLL")]
    public static extern bool SetLevel(byte[] byteArray, int high);
    
    byte[] byteArray = new byte[] { 0, 75, 0, 0, 0};
    SetLevel(byteArray, byteArray.Length-1);
    

    To be clear, in spite of the parameter lists looking so different, the C# code above will successfully call the Delphi DLL function declared so:

    function SetLevel(a: array of byte): boolean; stdcall;
    

    I have no idea whether or not passing an array of length 5 is appropriate, or whether you really meant to just set the second item to a non-zero value.

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

Sidebar

Related Questions

I need to convert this code into Delphi. But it's too complicated to handle...
I created a function similar below in delphi code. but it wont work. What
How do I convert a byte array to a string (base 256) in Delphi?
I'm trying to convert this code fragment into Delphi and I got stuck on
I am trying to convert a C code to Delphi/pascal, but somehow I cannot
I'm trying to convert an old Delphi program I wrote into Java to compile
Im trying to convert some Delphi code to c# and I've come across a
i need a tool that can convert c/c++ code to delphi(object pascal) code, have
I have some VB source code and want to convert it to Delphi: Do
Download source code here: http://www.eyeClaxton.com/download/delphi/ColorSwap.zip Yes, I want to convert something mostly blue to

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.