From 970f368450f851d2b0712e68e99ebca4ac4fdf6a Mon Sep 17 00:00:00 2001 From: Jens Wallauer <Wallauer@rhd-instruments.de> Date: Mon, 29 Apr 2024 17:32:37 +0200 Subject: [PATCH] Fixed missing pointer increment. Changed P/Invoke charset to Unicode. --- src/capi.cs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/capi.cs b/src/capi.cs index 18871c0..ec8c346 100644 --- a/src/capi.cs +++ b/src/capi.cs @@ -27,52 +27,52 @@ internal class Capi { public delegate void resultDlg(IntPtr result, ref CNetwork network, IntPtr data); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, EntryPoint = "kiss_free", CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, EntryPoint = "kiss_free", CallingConvention=CallingConvention.StdCall)] public static extern void free(IntPtr ptr); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern IntPtr kiss_create_range(float start, float end, UIntPtr length, byte log); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern void kiss_resample_spectra(float[] in_re, float[] in_im, UIntPtr input_length, ref IntPtr ret_ptr_real, ref IntPtr ret_ptr_imag, UIntPtr output_length); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern void kiss_normalize_spectra(float[] in_re, float[] in_im, UIntPtr input_length); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern IntPtr kiss_absgrad(float[] in_re, float[] in_im, float[] omegas, UIntPtr input_length, UIntPtr index); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern float kiss_grad(float[] data, float[] omegas, UIntPtr input_length, UIntPtr index); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern float kiss_median(float[] data, UIntPtr input_length); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern byte kiss_reduce_spectra(float[] in_re, float[] in_im, float[] omegas, UIntPtr input_length, float thresh_factor, byte use_second_deriv, ref IntPtr out_re, ref IntPtr out_im, ref UIntPtr output_length); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern byte kiss_filter_spectra(float[] in_re, float[] in_im, float[] omegas, UIntPtr input_length, ref IntPtr out_re, ref IntPtr out_im, UIntPtr output_length); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern byte kiss_load_network_prealloc(ref CNetwork net, string path, resultDlg callback, byte verbose); - [DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("libc", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern void puts(string path); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern void kiss_free_network_prealloc(ref CNetwork net); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern byte kiss_async_run_inference(ref CNetwork net, [Out] float[] inputs, IntPtr data); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern byte kiss_async_run_inference_complex(ref CNetwork net, [Out] float[] real, [Out] float[] imag, IntPtr data); - [DllImport("kissinference", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention=CallingConvention.StdCall)] + [DllImport("kissinference", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention=CallingConvention.StdCall)] public static extern IntPtr kiss_get_strerror(ref CNetwork net); public static string[] IntPtrToUtf8Array(IntPtr array) @@ -107,6 +107,7 @@ internal class Capi break; bytes.Add(b); + idx++; } return System.Text.Encoding.UTF8.GetString(bytes.ToArray()); -- GitLab