我正在尝试将一个字符串从C#传递到C DLL。根据我所读的,.NET应该为我执行从字符串到char*的转换,但是我得到了“error CS1503:Argument'1':无法从'string'转换为'char *'”的错误。有人能告诉我我错在哪里吗?谢谢。
C#代码
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))
{
}
}
C DLL
extern "C"
{
__declspec(dllexport) bool __cdecl StreamReceiveInitialise(char* filepath);
}