将字符串从C#传递给C DLL

int*_*753 6 c c# string dll char

我试图将字符串从C#传递给C DLL.从我读到的.NET应该为我做从字符串到char*的转换,但是我得到"错误CS1503:参数'1':无法从'字符串'转换为'字符*'"有人可以告诉我我在哪里出了什么问题?谢谢.

C#代码

[DllImport("Source.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static unsafe extern bool StreamReceiveInitialise(char* filepath);

const string test = "test";
// This method that will be called when the thread is started
public void Stream()
{
    if (StreamReceiveInitialise(test))
    {


    }
}
Run Code Online (Sandbox Code Playgroud)

C DLL

extern "C"
{
    __declspec(dllexport) bool __cdecl StreamReceiveInitialise(char* filepath);
}
Run Code Online (Sandbox Code Playgroud)

Ric*_*lly 3

将您的外部方法声明为:

public static extern bool StreamReceiveInitialise(string filepath);
Run Code Online (Sandbox Code Playgroud)