用c#重写Delphi dll调用
本文关键字:dll 调用 Delphi 重写 | 更新日期: 2023-09-27 18:12:41
我想用c#编写一个DMX Lightcontrol软件。我的问题是,我必须重写dll调用从Delphi到c#。下面的代码显示了我的尝试:
//delphi代码:
function GetDMXInterface: pchar; stdcall; external 'DMX510.dll';
function SetLevel(a: array of byte): boolean; stdcall; external 'DMX510.dll';
function GetMaxChannels: integer; external 'DMX510.dll';
//我自己的c#代码:
[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();
下一个问题如何将GetDMXInterface()返回的char指针转换为String
谢谢你的帮助!
尝试,但我不知道它是否有效,因为我无法测试它:
[DllImport("DMX510.DLL")]
public static extern StringBuilder GetDMXInterface();
或
[DllImport("DMX510.DLL", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr GetDMXInterface();
和
IntPtr ptr = GetDMXInterface();
string msg = Marshal.PtrToStringAuto(ptr);