1
votes

I want to write a DMX Lightcontrol software in C#. My problem is that I've to rewrite the DLL-calls from Delphi to C#. Following code shows my attempts:

//Delphi-Code:

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

//My own C#-Code:

[DllImport("DMX510.DLL")]
public static extern char* GetDMXInterface();
[DllImport("DMX510.DLL")]
public static extern Boolean SetLevel(Byte[] bytearray);
[DllImport("DMX510.DLL")]
public static extern int GetMaxChannels();

Next question how to convert the char pointer returned from GetDMXInterface() to a String

Thanks for your help!

1
you have this: stackoverflow.com/questions/508227/… Sounds perfect for you...Stef

1 Answers

2
votes

Try, but I don't know if it works because I cannot test it:

[DllImport("DMX510.DLL")]
public static extern StringBuilder GetDMXInterface();

Or try

[DllImport("DMX510.DLL", CharSet = CharSet.Unicode, 
 CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr GetDMXInterface();

and then

IntPtr ptr = GetDMXInterface(); 
string msg = Marshal.PtrToStringAuto(ptr);