0
Я просто пытаюсь передать буфер в C dll из C#, чтобы C func заполнил буфер, а затем сделайте что-то с буфером в коде C#. Но я возвращаю мусор обратно в буфер. Вот C:изменить массив символов, переданный в C dll C#
extern "C" __declspec(dllexport)
int cFunction(char *plotInfo, int bufferSize)
{
strcpy(plotInfo, "text");
return(0);
}
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
[DllImport("mcDll.dll",
CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Unicode)]
public static extern int cFunction(StringBuilder theString, int bufferSize);
static void Main(string[] args)
{
StringBuilder s = new StringBuilder(55);
int result = cFunction(s, 55);
Console.WriteLine(s);
}
}
}