有:
[DllImport("OpenAL32.dll")]
static extern void alcOpenDevice(char*[] devicename);
想要将名称发送给这个函数,就像这样:
char[] data = "Hello!".ToCharArray();
char*[] txt = &data;
但是出现错误:
-
cannot implicitly convert type
char[] *
tochar * []
(有趣的错误,因为 C# 编译器也拒绝在/unsafe 模式下定义
char[] *
:)) -
Cannot take the address of, get the size of, or declare a pointer to a managed type (
char[]
)
附言
char
什么时候变成托管的?这是一个结构,不是吗?
public struct Char : IComparable, IConvertible, IComparable<char>, IEquatable<char>
尽管编译器显示了有关声明指向托管类型 (char[]
) 的指针的信息。我只能建议,当类型是数组时,CLR 可能会将其呈现为托管类型,但这听起来很疯狂。
最佳答案
alcOpenDevice 不采用 char*[]
或 char**
,它采用 char*
,您应该将其指定为 字符串
。它还返回一个句柄。
[DllImport("OpenAL32.dll", CharSet = CharSet.Ansi)]
static extern IntPtr alcOpenDevice(string devicename);
关于C# 不安全类型 -> char*[] ,获取 char 数组上的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14086502/