我正在尝试将字符串从 C# 传递到 C DLL。根据我的阅读,.NET 应该为我完成从字符串到 char* 的转换,但是我得到“错误 CS1503:参数‘1’:无法从‘string’转换为‘char*’”有人能告诉我我在哪里有错吗?谢谢。
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))
{
}
}
动态链接库
extern "C"
{
__declspec(dllexport) bool __cdecl StreamReceiveInitialise(char* filepath);
}
最佳答案
将您的外部方法声明为:
public static extern bool StreamReceiveInitialise(string filepath);
关于c# - 将字符串从 C# 传递到 C DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8896030/